From aa0321df8f2b6799c278b552dbbbc6a94b0d3333 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Mon, 23 Dec 2024 18:36:14 -0300 Subject: [PATCH] fix: continue http downloads --- python_rpc/main.py | 2 - src/main/main.ts | 7 +- .../services/download/download-manager.ts | 74 +++++++++---------- 3 files changed, 37 insertions(+), 46 deletions(-) diff --git a/python_rpc/main.py b/python_rpc/main.py index 54e5038f..36c0a922 100644 --- a/python_rpc/main.py +++ b/python_rpc/main.py @@ -124,8 +124,6 @@ def action(): action = data.get('action') game_id = data.get('game_id') - print(data) - if action == 'start': url = data.get('url') diff --git a/src/main/main.ts b/src/main/main.ts index 8c566123..5522becb 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -9,7 +9,6 @@ import { RealDebridClient } from "./services/download/real-debrid"; import { HydraApi } from "./services/hydra-api"; import { uploadGamesBatch } from "./services/library-sync"; import { Aria2 } from "./services/aria2"; -import { PythonRPC } from "./services/python-rpc"; const loadState = async (userPreferences: UserPreferences | null) => { import("./events"); @@ -43,11 +42,7 @@ const loadState = async (userPreferences: UserPreferences | null) => { }, }); - if (nextQueueItem?.game.status === "active") { - DownloadManager.startRPC(nextQueueItem.game, seedList); - } else { - PythonRPC.spawn(); - } + await DownloadManager.startRPC(nextQueueItem?.game, seedList); startMainLoop(); }; diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index 3a8da5b4..e6020cbc 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -24,23 +24,19 @@ import { logger } from "../logger"; export class DownloadManager { private static downloadingGameId: number | null = null; - public static startRPC(game: Game, initialSeeding?: Game[]) { - if (game && game.status === "active") { - PythonRPC.spawn( - { - game_id: game.id, - url: game.uri!, - save_path: game.downloadPath!, - }, - initialSeeding?.map((game) => ({ - game_id: game.id, - url: game.uri!, - save_path: game.downloadPath!, - })) - ); + public static async startRPC(game?: Game, initialSeeding?: Game[]) { + PythonRPC.spawn( + game?.status === "active" + ? await this.getDownloadPayload(game).catch(() => undefined) + : undefined, + initialSeeding?.map((game) => ({ + game_id: game.id, + url: game.uri!, + save_path: game.downloadPath!, + })) + ); - this.downloadingGameId = game.id; - } + this.downloadingGameId = game?.id ?? null; } private static async getDownloadStatus() { @@ -245,7 +241,7 @@ export class DownloadManager { }); } - static async startDownload(game: Game) { + private static async getDownloadPayload(game: Game) { switch (game.downloader) { case Downloader.Gofile: { const id = game!.uri!.split("/").pop(); @@ -253,56 +249,58 @@ export class DownloadManager { const token = await GofileApi.authorize(); const downloadLink = await GofileApi.getDownloadLink(id!); - await PythonRPC.rpc.post("/action", { + return { action: "start", game_id: game.id, url: downloadLink, - save_path: game.downloadPath, + save_path: game.downloadPath!, header: `Cookie: accountToken=${token}`, - }); - break; + }; } case Downloader.PixelDrain: { const id = game!.uri!.split("/").pop(); - await PythonRPC.rpc.post("/action", { + return { action: "start", game_id: game.id, url: `https://pixeldrain.com/api/file/${id}?download`, - save_path: game.downloadPath, - }); - break; + save_path: game.downloadPath!, + }; } case Downloader.Qiwi: { const downloadUrl = await QiwiApi.getDownloadUrl(game.uri!); - await PythonRPC.rpc.post("/action", { + return { action: "start", game_id: game.id, url: downloadUrl, - save_path: game.downloadPath, - }); - break; + save_path: game.downloadPath!, + }; } case Downloader.Torrent: - await PythonRPC.rpc.post("/action", { + return { action: "start", game_id: game.id, - url: game.uri, - save_path: game.downloadPath, - }); - break; + url: game.uri!, + save_path: game.downloadPath!, + }; case Downloader.RealDebrid: { const downloadUrl = await RealDebridClient.getDownloadUrl(game.uri!); - await PythonRPC.rpc.post("/action", { + return { action: "start", game_id: game.id, - url: downloadUrl, - save_path: game.downloadPath, - }); + url: downloadUrl!, + save_path: game.downloadPath!, + }; } } + } + + static async startDownload(game: Game) { + const payload = await this.getDownloadPayload(game); + + await PythonRPC.rpc.post("/action", payload); this.downloadingGameId = game.id; }