Merge branch 'feat/real-debrid-integration' of https://github.com/hydralauncher/hydra into feat/real-debrid-integration

This commit is contained in:
lilezek 2024-05-06 11:38:29 +02:00
commit 31ad209dda

View file

@ -8,6 +8,10 @@ import { fullArchive } from "node-7z-archive";
import { Downloader } from "./downloader"; import { Downloader } from "./downloader";
import { RealDebridClient } from "../real-debrid"; import { RealDebridClient } from "../real-debrid";
function getFileNameWithoutExtension(fullPath: string) {
return path.basename(fullPath, path.extname(fullPath));
}
export class RealDebridDownloader extends Downloader { export class RealDebridDownloader extends Downloader {
private static download: EasyDL; private static download: EasyDL;
private static downloadSize = 0; private static downloadSize = 0;
@ -30,6 +34,7 @@ export class RealDebridDownloader extends Downloader {
downloadUrl, downloadUrl,
path.join(game.downloadPath!, ".rd") path.join(game.downloadPath!, ".rd")
); );
const metadata = await this.download.metadata(); const metadata = await this.download.metadata();
this.downloadSize = metadata.size; this.downloadSize = metadata.size;
@ -37,7 +42,7 @@ export class RealDebridDownloader extends Downloader {
const updatePayload: QueryDeepPartialEntity<Game> = { const updatePayload: QueryDeepPartialEntity<Game> = {
status: GameStatus.Downloading, status: GameStatus.Downloading,
fileSize: metadata.size, fileSize: metadata.size,
folderName: game.repack.title, folderName: getFileNameWithoutExtension(metadata.savedFilePath),
}; };
const downloadStatus = { const downloadStatus = {
@ -71,12 +76,12 @@ export class RealDebridDownloader extends Downloader {
timeRemaining: 0, timeRemaining: 0,
}); });
this.startDecompression(this.download.savedFilePath!, game); this.startDecompression(this.download.savedFilePath!, getFileNameWithoutExtension(metadata.savedFilePath), game);
}); });
} }
static async startDecompression(rarFile: string, game: Game) { static async startDecompression(rarFile: string, destiny: string, game: Game) {
const directory = path.join(game.downloadPath!, game.repack.title); const directory = path.join(game.downloadPath!, destiny);
await fullArchive(rarFile, directory); await fullArchive(rarFile, directory);
const updatePayload: QueryDeepPartialEntity<Game> = { const updatePayload: QueryDeepPartialEntity<Game> = {