diff --git a/python_rpc/http_downloader.py b/python_rpc/http_downloader.py index 71e4b57e..88334fe9 100644 --- a/python_rpc/http_downloader.py +++ b/python_rpc/http_downloader.py @@ -1,48 +1,61 @@ import aria2p class HttpDownloader: - def __init__(self): - self.download = None - self.aria2 = aria2p.API( - aria2p.Client( - host="http://localhost", - port=6800, - secret="" - ) - ) + def __init__(self): + self.download = None + self.aria2 = aria2p.API( + aria2p.Client( + host="http://localhost", + port=6800, + secret="" + ) + ) - def start_download(self, url: str, save_path: str, header: str, out: str = None): - if self.download: - self.aria2.resume([self.download]) - else: - downloads = self.aria2.add(url, options={"header": header, "dir": save_path, "out": out}) - - self.download = downloads[0] - - def pause_download(self): - if self.download: - self.aria2.pause([self.download]) - - def cancel_download(self): - if self.download: - self.aria2.remove([self.download]) - self.download = None + def start_download(self, url: str, save_path: str, header: str, out: str = None, allow_multiple_connections: bool = False): + if self.download: + self.aria2.resume([self.download]) + else: + options = { + "header": header, + "dir": save_path, + "out": out + } - def get_download_status(self): - if self.download == None: - return None + if allow_multiple_connections: + options.update({ + "split": "16", + "max-connection-per-server": "16", + "min-split-size": "1M" + }) + + downloads = self.aria2.add(url, options=options) + + self.download = downloads[0] + + def pause_download(self): + if self.download: + self.aria2.pause([self.download]) + + def cancel_download(self): + if self.download: + self.aria2.remove([self.download]) + self.download = None - download = self.aria2.get_download(self.download.gid) + def get_download_status(self): + if self.download == None: + return None - response = { - 'folderName': download.name, - 'fileSize': download.total_length, - 'progress': download.completed_length / download.total_length if download.total_length else 0, - 'downloadSpeed': download.download_speed, - 'numPeers': 0, - 'numSeeds': 0, - 'status': download.status, - 'bytesDownloaded': download.completed_length, - } + download = self.aria2.get_download(self.download.gid) - return response + response = { + 'folderName': download.name, + 'fileSize': download.total_length, + 'progress': download.completed_length / download.total_length if download.total_length else 0, + 'downloadSpeed': download.download_speed, + 'numPeers': 0, + 'numSeeds': 0, + 'status': download.status, + 'bytesDownloaded': download.completed_length, + } + + return response \ No newline at end of file diff --git a/python_rpc/main.py b/python_rpc/main.py index 94c34e17..915f1670 100644 --- a/python_rpc/main.py +++ b/python_rpc/main.py @@ -147,11 +147,11 @@ def action(): torrent_downloader.start_download(url, data['save_path']) else: if existing_downloader and isinstance(existing_downloader, HttpDownloader): - existing_downloader.start_download(url, data['save_path'], data.get('header'), data.get('out')) + existing_downloader.start_download(url, data['save_path'], data.get('header'), data.get('out'), data.get('allow_multiple_connections', False)) else: http_downloader = HttpDownloader() downloads[game_id] = http_downloader - http_downloader.start_download(url, data['save_path'], data.get('header'), data.get('out')) + http_downloader.start_download(url, data['save_path'], data.get('header'), data.get('out'), data.get('allow_multiple_connections', False)) downloading_game_id = game_id diff --git a/scripts/postinstall.cjs b/scripts/postinstall.cjs index fc3f69dd..6df98f54 100644 --- a/scripts/postinstall.cjs +++ b/scripts/postinstall.cjs @@ -123,3 +123,10 @@ const copyAria2 = () => { copyAria2(); downloadLudusavi(); + +if (process.platform !== "win32") { + const binariesPath = path.join(__dirname, "..", "binaries"); + + fs.chmodSync(path.join(binariesPath, "7zz"), 0o755); + fs.chmodSync(path.join(binariesPath, "7zzs"), 0o755); +} diff --git a/src/main/services/7zip.ts b/src/main/services/7zip.ts index 08abf389..20315b2f 100644 --- a/src/main/services/7zip.ts +++ b/src/main/services/7zip.ts @@ -45,13 +45,13 @@ export class SevenZip { args.push("-o" + outputPath); } + console.log(this.binaryPath, args); + const child = cp.execFile(this.binaryPath, args, { cwd, }); child.once("exit", (code) => { - console.log("EXIT CALLED", code, filePath); - if (code === 0) { successCb(); return; diff --git a/src/main/services/aria2.ts b/src/main/services/aria2.ts index a927a1bd..98fd0e13 100644 --- a/src/main/services/aria2.ts +++ b/src/main/services/aria2.ts @@ -16,12 +16,6 @@ export class Aria2 { "--rpc-listen-all", "--file-allocation=none", "--allow-overwrite=true", - "-s", - "16", - "-x", - "16", - "-k", - "1M", ], { stdio: "inherit", windowsHide: true } ); diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index 9eba39f3..35841d33 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -371,6 +371,7 @@ export class DownloadManager { game_id: downloadId, url: downloadUrl, save_path: download.downloadPath, + allow_multiple_connections: true, }; } case Downloader.TorBox: { @@ -383,6 +384,7 @@ export class DownloadManager { url, save_path: download.downloadPath, out: name, + allow_multiple_connections: true, }; } }