Fixing downloads by replacing the torrent client

This commit is contained in:
tuesday 2024-06-26 17:58:05 +02:00
parent 2aeeeaf15b
commit fea59514bc
2 changed files with 51 additions and 49 deletions

View File

@ -3,35 +3,37 @@ import { spawn } from "node:child_process";
import { app } from "electron";
export const startAria2 = () => {
const binaryPath = app.isPackaged
? path.join(process.resourcesPath, "aria2", "aria2c")
: path.join(__dirname, "..", "..", "aria2", "aria2c");
const binaryPath = app.isPackaged
? path.join(process.resourcesPath, "aria2", "aria2c")
: path.join(__dirname, "..", "..", "aria2", "aria2c");
const aria2Process = spawn(
binaryPath,
[
"--enable-rpc",
"--rpc-listen-all",
"--file-allocation=none",
"--allow-overwrite=true",
"--log-level=debug",
"--no-conf",
"--disk-cache=128M"
],
{ stdio: "inherit", windowsHide: true }
);
const aria2Process = spawn(
binaryPath,
[
"--enable-rpc",
"--rpc-listen-all",
"--file-allocation=none",
"--allow-overwrite=true",
"--log-level=debug",
"--no-conf",
"--disk-cache=128M",
],
{ stdio: "inherit", windowsHide: true }
);
aria2Process.on("error", (err) => {
console.error("Aria2 process error:", err);
});
aria2Process.on("error", (err) => {
console.error("Aria2 process error:", err);
});
aria2Process.on("exit", (code, signal) => {
if (code !== 0) {
console.error(`Aria2 process exited with code ${code} and signal ${signal}`);
} else {
console.log("Aria2 process exited successfully");
}
});
aria2Process.on("exit", (code, signal) => {
if (code !== 0) {
console.error(
`Aria2 process exited with code ${code} and signal ${signal}`
);
} else {
console.log("Aria2 process exited successfully");
}
});
return aria2Process;
return aria2Process;
};

View File

@ -55,9 +55,9 @@ export class DownloadManager {
}
private static getETA(
totalLength: number,
completedLength: number,
speed: number
totalLength: number,
completedLength: number,
speed: number
) {
const remainingBytes = totalLength - completedLength;
@ -80,7 +80,7 @@ export class DownloadManager {
private static async getRealDebridDownloadUrl() {
if (this.realDebridTorrentId) {
const torrentInfo = await RealDebridClient.getTorrentInfo(
this.realDebridTorrentId
this.realDebridTorrentId
);
const { status, links } = torrentInfo;
@ -107,9 +107,9 @@ export class DownloadManager {
numSeeds: torrentInfo.seeders,
downloadSpeed: torrentInfo.speed,
timeRemaining: this.getETA(
torrentInfo.bytes,
totalDownloaded,
torrentInfo.speed
torrentInfo.bytes,
totalDownloaded,
torrentInfo.speed
),
isDownloadingMetadata: status === "magnet_conversion",
game: {
@ -120,8 +120,8 @@ export class DownloadManager {
} as DownloadProgress;
WindowManager.mainWindow.webContents.send(
"on-download-progress",
JSON.parse(JSON.stringify(payload))
"on-download-progress",
JSON.parse(JSON.stringify(payload))
);
}
}
@ -156,7 +156,7 @@ export class DownloadManager {
}
const progress =
Number(status.completedLength) / Number(status.totalLength);
Number(status.completedLength) / Number(status.totalLength);
if (!isDownloadingMetadata) {
const update: QueryDeepPartialEntity<Game> = {
@ -168,12 +168,12 @@ export class DownloadManager {
if (!isNaN(progress)) update.progress = progress;
await gameRepository.update(
{ id: this.game.id },
{
...update,
status: status.status,
folderName: this.getFolderName(status),
}
{ id: this.game.id },
{
...update,
status: status.status,
folderName: this.getFolderName(status),
}
);
}
@ -190,17 +190,17 @@ export class DownloadManager {
numSeeds: Number(status.numSeeders ?? 0),
downloadSpeed: Number(status.downloadSpeed),
timeRemaining: this.getETA(
Number(status.totalLength),
Number(status.completedLength),
Number(status.downloadSpeed)
Number(status.totalLength),
Number(status.completedLength),
Number(status.downloadSpeed)
),
isDownloadingMetadata: !!isDownloadingMetadata,
game,
} as DownloadProgress;
WindowManager.mainWindow.webContents.send(
"on-download-progress",
JSON.parse(JSON.stringify(payload))
"on-download-progress",
JSON.parse(JSON.stringify(payload))
);
}
@ -292,7 +292,7 @@ export class DownloadManager {
if (game.downloader === Downloader.RealDebrid) {
this.realDebridTorrentId = await RealDebridClient.getTorrentId(
game!.uri!
game!.uri!
);
} else {
this.gid = await this.aria2.call("addUri", [game.uri!], options);