mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
refactor: rename of the http downloader to real debrid downloader given that it only supports downloading games through real debrid
This commit is contained in:
parent
73c65640e1
commit
9cd8188f06
6 changed files with 40 additions and 41 deletions
|
@ -26,7 +26,7 @@ const startGameDownload = async (
|
||||||
});
|
});
|
||||||
|
|
||||||
const downloader = userPreferences?.realDebridApiToken
|
const downloader = userPreferences?.realDebridApiToken
|
||||||
? Downloader.Http
|
? Downloader.RealDebrid
|
||||||
: Downloader.Torrent;
|
: Downloader.Torrent;
|
||||||
|
|
||||||
const [game, repack] = await Promise.all([
|
const [game, repack] = await Promise.all([
|
||||||
|
|
|
@ -4,7 +4,7 @@ import type { Game } from "@main/entity";
|
||||||
import { Downloader } from "@shared";
|
import { Downloader } from "@shared";
|
||||||
|
|
||||||
import { writePipe } from "./fifo";
|
import { writePipe } from "./fifo";
|
||||||
import { HTTPDownloader } from "./downloaders";
|
import { RealDebridDownloader } from "./downloaders";
|
||||||
|
|
||||||
export class DownloadManager {
|
export class DownloadManager {
|
||||||
private static gameDownloading: Game;
|
private static gameDownloading: Game;
|
||||||
|
@ -25,7 +25,7 @@ export class DownloadManager {
|
||||||
) {
|
) {
|
||||||
writePipe.write({ action: "cancel" });
|
writePipe.write({ action: "cancel" });
|
||||||
} else {
|
} else {
|
||||||
HTTPDownloader.destroy();
|
RealDebridDownloader.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ export class DownloadManager {
|
||||||
) {
|
) {
|
||||||
writePipe.write({ action: "pause" });
|
writePipe.write({ action: "pause" });
|
||||||
} else {
|
} else {
|
||||||
HTTPDownloader.destroy();
|
RealDebridDownloader.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ export class DownloadManager {
|
||||||
save_path: game!.downloadPath,
|
save_path: game!.downloadPath,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
HTTPDownloader.startDownload(game!);
|
RealDebridDownloader.startDownload(game!);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.gameDownloading = game!;
|
this.gameDownloading = game!;
|
||||||
|
@ -68,7 +68,7 @@ export class DownloadManager {
|
||||||
save_path: game!.downloadPath,
|
save_path: game!.downloadPath,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
HTTPDownloader.startDownload(game!);
|
RealDebridDownloader.startDownload(game!);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.gameDownloading = game!;
|
this.gameDownloading = game!;
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
export * from "./http.downloader";
|
export * from "./real-debrid.downloader";
|
||||||
export * from "./torrent.downloader";
|
export * from "./torrent.downloader";
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { GameStatus } from "@shared";
|
||||||
import { Downloader } from "./downloader";
|
import { Downloader } from "./downloader";
|
||||||
import { RealDebridClient } from "../real-debrid";
|
import { RealDebridClient } from "../real-debrid";
|
||||||
|
|
||||||
export class HTTPDownloader extends Downloader {
|
export class RealDebridDownloader extends Downloader {
|
||||||
private static download: EasyDL;
|
private static download: EasyDL;
|
||||||
private static downloadSize = 0;
|
private static downloadSize = 0;
|
||||||
|
|
||||||
|
@ -21,43 +21,14 @@ export class HTTPDownloader extends Downloader {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getDownloadUrl(game: Game) {
|
|
||||||
const torrents = await RealDebridClient.getAllTorrentsFromUser();
|
|
||||||
const hash = RealDebridClient.extractSHA1FromMagnet(game!.repack.magnet);
|
|
||||||
let torrent = torrents.find((t) => t.hash === hash);
|
|
||||||
|
|
||||||
if (!torrent) {
|
|
||||||
const magnet = await RealDebridClient.addMagnet(game!.repack.magnet);
|
|
||||||
|
|
||||||
if (magnet && magnet.id) {
|
|
||||||
await RealDebridClient.selectAllFiles(magnet.id);
|
|
||||||
torrent = await RealDebridClient.getInfo(magnet.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (torrent) {
|
|
||||||
const { links } = torrent;
|
|
||||||
const { download } = await RealDebridClient.unrestrictLink(links[0]);
|
|
||||||
|
|
||||||
if (!download) {
|
|
||||||
throw new Error("Torrent not cached on Real Debrid");
|
|
||||||
}
|
|
||||||
|
|
||||||
return download;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error();
|
|
||||||
}
|
|
||||||
|
|
||||||
static async startDownload(game: Game) {
|
static async startDownload(game: Game) {
|
||||||
if (this.download) this.download.destroy();
|
if (this.download) this.download.destroy();
|
||||||
const download = await this.getDownloadUrl(game);
|
const downloadUrl = await RealDebridClient.getDownloadUrl(game);
|
||||||
|
|
||||||
this.download = new EasyDL(
|
this.download = new EasyDL(
|
||||||
download,
|
downloadUrl,
|
||||||
path.join(game.downloadPath!, game.repack.title)
|
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;
|
|
@ -62,6 +62,34 @@ export class RealDebridClient {
|
||||||
return magnet.match(/btih:([0-9a-fA-F]*)/)?.[1].toLowerCase();
|
return magnet.match(/btih:([0-9a-fA-F]*)/)?.[1].toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getDownloadUrl(game: Game) {
|
||||||
|
const torrents = await RealDebridClient.getAllTorrentsFromUser();
|
||||||
|
const hash = RealDebridClient.extractSHA1FromMagnet(game!.repack.magnet);
|
||||||
|
let torrent = torrents.find((t) => t.hash === hash);
|
||||||
|
|
||||||
|
if (!torrent) {
|
||||||
|
const magnet = await RealDebridClient.addMagnet(game!.repack.magnet);
|
||||||
|
|
||||||
|
if (magnet && magnet.id) {
|
||||||
|
await RealDebridClient.selectAllFiles(magnet.id);
|
||||||
|
torrent = await RealDebridClient.getInfo(magnet.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (torrent) {
|
||||||
|
const { links } = torrent;
|
||||||
|
const { download } = await RealDebridClient.unrestrictLink(links[0]);
|
||||||
|
|
||||||
|
if (!download) {
|
||||||
|
throw new Error("Torrent not cached on Real Debrid");
|
||||||
|
}
|
||||||
|
|
||||||
|
return download;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
|
||||||
static async authorize(apiToken: string) {
|
static async authorize(apiToken: string) {
|
||||||
this.instance = axios.create({
|
this.instance = axios.create({
|
||||||
baseURL: base,
|
baseURL: base,
|
||||||
|
|
|
@ -9,7 +9,7 @@ export enum GameStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Downloader {
|
export enum Downloader {
|
||||||
Http,
|
RealDebrid,
|
||||||
Torrent,
|
Torrent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue