diff --git a/src/main/main.ts b/src/main/main.ts index add619e1..81916174 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -11,6 +11,7 @@ import { uploadGamesBatch } from "./services/library-sync"; import { Aria2 } from "./services/aria2"; import { Downloader } from "@shared"; import { IsNull, Not } from "typeorm"; +import { TorBoxClient } from "./services/download/torbox"; const loadState = async (userPreferences: UserPreferences | null) => { import("./events"); @@ -21,6 +22,8 @@ const loadState = async (userPreferences: UserPreferences | null) => { RealDebridClient.authorize(userPreferences?.realDebridApiToken); } + TorBoxClient.authorize("7371d5ec-52fa-4b87-9052-0c8c96d947cc"); + Ludusavi.addManifestToLudusaviConfig(); HydraApi.setupApi().then(() => { diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index 80a3f6fb..1c91c4dc 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -20,6 +20,7 @@ import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity import { RealDebridClient } from "./real-debrid"; import path from "path"; import { logger } from "../logger"; +import { TorBoxClient } from "./torbox"; export class DownloadManager { private static downloadingGameId: number | null = null; @@ -29,6 +30,7 @@ export class DownloadManager { game?.status === "active" ? await this.getDownloadPayload(game).catch(() => undefined) : undefined, + initialSeeding?.map((game) => ({ game_id: game.id, url: game.uri!, @@ -294,6 +296,18 @@ export class DownloadManager { save_path: game.downloadPath!, }; } + case Downloader.TorBox: { + const downloadUrl = await TorBoxClient.getDownloadUrl(game.uri!); + console.log(downloadUrl); + + if (!downloadUrl) return; + return { + action: "start", + game_id: game.id, + url: downloadUrl, + save_path: game.downloadPath!, + }; + } } } diff --git a/src/main/services/download/torbox.ts b/src/main/services/download/torbox.ts index 3eade81d..1ef57768 100644 --- a/src/main/services/download/torbox.ts +++ b/src/main/services/download/torbox.ts @@ -20,7 +20,7 @@ export class TorBoxClient { Authorization: `Bearer ${apiToken}`, }, }); - this.apiToken = apiToken; + this.apiToken = "7371d5ec-52fa-4b87-9052-0c8c96d947cc"; } static async addMagnet(magnet: string) { @@ -55,22 +55,16 @@ export class TorBoxClient { } static async requestLink(id: number) { - const searchParams = new URLSearchParams({}); - - searchParams.set("token", this.apiToken); - searchParams.set("torrent_id", id.toString()); - searchParams.set("zip_link", "true"); + const searchParams = new URLSearchParams({ + token: this.apiToken, + torrent_id: id.toString(), + zip_link: "true", + }); const response = await this.instance.get( "/torrents/requestdl?" + searchParams.toString() ); - if (response.status !== 200) { - logger.error(response.data.error); - logger.error(response.data.detail); - return null; - } - return response.data.data; } @@ -94,4 +88,9 @@ export class TorBoxClient { const torrent = await this.addMagnet(magnetUri); return torrent.torrent_id; } + + static async getDownloadUrl(uri: string) { + const id = await this.getTorrentId(uri); + return this.requestLink(id); + } } diff --git a/src/renderer/src/assets/icons/torbox.webp b/src/renderer/src/assets/icons/torbox.webp new file mode 100644 index 00000000..68d68531 Binary files /dev/null and b/src/renderer/src/assets/icons/torbox.webp differ diff --git a/src/renderer/src/constants.ts b/src/renderer/src/constants.ts index 74541837..05b43c92 100644 --- a/src/renderer/src/constants.ts +++ b/src/renderer/src/constants.ts @@ -8,6 +8,7 @@ export const DOWNLOADER_NAME = { [Downloader.Gofile]: "Gofile", [Downloader.PixelDrain]: "PixelDrain", [Downloader.Qiwi]: "Qiwi", + [Downloader.TorBox]: "TorBox", }; export const MAX_MINUTES_TO_SHOW_IN_PLAYTIME = 120; diff --git a/src/renderer/src/pages/downloads/download-group.tsx b/src/renderer/src/pages/downloads/download-group.tsx index 88cf1433..a5dfa8fe 100644 --- a/src/renderer/src/pages/downloads/download-group.tsx +++ b/src/renderer/src/pages/downloads/download-group.tsx @@ -31,6 +31,8 @@ import { XCircleIcon, } from "@primer/octicons-react"; +import torBoxLogo from "@renderer/assets/icons/torbox.webp"; + export interface DownloadGroupProps { library: LibraryGame[]; title: string; @@ -276,7 +278,28 @@ export function DownloadGroup({ />
- {DOWNLOADER_NAME[game.downloader]} + {game.downloader === Downloader.TorBox ? ( +
+ TorBox + TorBox +
+ ) : ( + {DOWNLOADER_NAME[game.downloader]} + )}
diff --git a/src/renderer/src/pages/game-details/modals/download-settings-modal.tsx b/src/renderer/src/pages/game-details/modals/download-settings-modal.tsx index 191d9ac1..8d650c17 100644 --- a/src/renderer/src/pages/game-details/modals/download-settings-modal.tsx +++ b/src/renderer/src/pages/game-details/modals/download-settings-modal.tsx @@ -68,11 +68,9 @@ export function DownloadSettingsModal({ return true; }); - /* Gives preference to Real Debrid */ - const selectedDownloader = filteredDownloaders.includes( - Downloader.RealDebrid - ) - ? Downloader.RealDebrid + /* Gives preference to TorBox */ + const selectedDownloader = filteredDownloaders.includes(Downloader.TorBox) + ? Downloader.TorBox : filteredDownloaders[0]; setSelectedDownloader( diff --git a/src/shared/constants.ts b/src/shared/constants.ts index 2d313abb..4ab7443d 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -4,6 +4,7 @@ export enum Downloader { Gofile, PixelDrain, Qiwi, + TorBox, } export enum DownloadSourceStatus { diff --git a/src/shared/index.ts b/src/shared/index.ts index 85868391..e0b09deb 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -92,7 +92,7 @@ export const getDownloadersForUri = (uri: string) => { return [Downloader.RealDebrid]; if (uri.startsWith("magnet:")) { - return [Downloader.Torrent, Downloader.RealDebrid]; + return [Downloader.Torrent, Downloader.TorBox, Downloader.RealDebrid]; } return [];