mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 05:24:55 +03:00
fix: possible fix for pixel drain and torbox cancel download
This commit is contained in:
parent
c9ae543d3e
commit
6ea1f9034b
@ -11,11 +11,12 @@ class HttpDownloader:
|
||||
)
|
||||
)
|
||||
|
||||
def start_download(self, url: str, save_path: str, header: str):
|
||||
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})
|
||||
downloads = self.aria2.add(url, options={"header": header, "dir": save_path, "out": out})
|
||||
|
||||
self.download = downloads[0]
|
||||
|
||||
def pause_download(self):
|
||||
|
@ -28,14 +28,14 @@ if start_download_payload:
|
||||
torrent_downloader = TorrentDownloader(torrent_session)
|
||||
downloads[initial_download['game_id']] = torrent_downloader
|
||||
try:
|
||||
torrent_downloader.start_download(initial_download['url'], initial_download['save_path'], "")
|
||||
torrent_downloader.start_download(initial_download['url'], initial_download['save_path'])
|
||||
except Exception as e:
|
||||
print("Error starting torrent download", e)
|
||||
else:
|
||||
http_downloader = HttpDownloader()
|
||||
downloads[initial_download['game_id']] = http_downloader
|
||||
try:
|
||||
http_downloader.start_download(initial_download['url'], initial_download['save_path'], initial_download.get('header'))
|
||||
http_downloader.start_download(initial_download['url'], initial_download['save_path'], initial_download.get('header'), initial_download.get("out"))
|
||||
except Exception as e:
|
||||
print("Error starting http download", e)
|
||||
|
||||
@ -45,7 +45,7 @@ if start_seeding_payload:
|
||||
torrent_downloader = TorrentDownloader(torrent_session, lt.torrent_flags.upload_mode)
|
||||
downloads[seed['game_id']] = torrent_downloader
|
||||
try:
|
||||
torrent_downloader.start_download(seed['url'], seed['save_path'], "")
|
||||
torrent_downloader.start_download(seed['url'], seed['save_path'])
|
||||
except Exception as e:
|
||||
print("Error starting seeding", e)
|
||||
|
||||
@ -140,18 +140,18 @@ def action():
|
||||
|
||||
if url.startswith('magnet'):
|
||||
if existing_downloader and isinstance(existing_downloader, TorrentDownloader):
|
||||
existing_downloader.start_download(url, data['save_path'], "")
|
||||
existing_downloader.start_download(url, data['save_path'])
|
||||
else:
|
||||
torrent_downloader = TorrentDownloader(torrent_session)
|
||||
downloads[game_id] = torrent_downloader
|
||||
torrent_downloader.start_download(url, data['save_path'], "")
|
||||
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'))
|
||||
existing_downloader.start_download(url, data['save_path'], data.get('header'), data.get('out'))
|
||||
else:
|
||||
http_downloader = HttpDownloader()
|
||||
downloads[game_id] = http_downloader
|
||||
http_downloader.start_download(url, data['save_path'], data.get('header'))
|
||||
http_downloader.start_download(url, data['save_path'], data.get('header'), data.get('out'))
|
||||
|
||||
downloading_game_id = game_id
|
||||
|
||||
@ -167,7 +167,7 @@ def action():
|
||||
elif action == 'resume_seeding':
|
||||
torrent_downloader = TorrentDownloader(torrent_session, lt.torrent_flags.upload_mode)
|
||||
downloads[game_id] = torrent_downloader
|
||||
torrent_downloader.start_download(data['url'], data['save_path'], "")
|
||||
torrent_downloader.start_download(data['url'], data['save_path'])
|
||||
elif action == 'pause_seeding':
|
||||
downloader = downloads.get(game_id)
|
||||
if downloader:
|
||||
|
@ -102,7 +102,7 @@ class TorrentDownloader:
|
||||
"http://bvarf.tracker.sh:2086/announce",
|
||||
]
|
||||
|
||||
def start_download(self, magnet: str, save_path: str, header: str):
|
||||
def start_download(self, magnet: str, save_path: str):
|
||||
params = {'url': magnet, 'save_path': save_path, 'trackers': self.trackers, 'flags': self.flags}
|
||||
self.torrent_handle = self.session.add_torrent(params)
|
||||
self.torrent_handle.resume()
|
||||
|
@ -2,7 +2,6 @@ import { registerEvent } from "../register-event";
|
||||
import { DownloadManager, HydraApi, gamesPlaytime } from "@main/services";
|
||||
import { dataSource } from "@main/data-source";
|
||||
import { DownloadQueue, Game, UserAuth, UserSubscription } from "@main/entity";
|
||||
import { PythonRPC } from "@main/services/python-rpc";
|
||||
|
||||
const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
const databaseOperations = dataSource
|
||||
@ -27,9 +26,6 @@ const signOut = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
/* Cancels any ongoing downloads */
|
||||
DownloadManager.cancelDownload();
|
||||
|
||||
/* Disconnects libtorrent */
|
||||
PythonRPC.kill();
|
||||
|
||||
HydraApi.handleSignOut();
|
||||
|
||||
await Promise.all([
|
||||
|
@ -21,6 +21,7 @@ import { RealDebridClient } from "./real-debrid";
|
||||
import path from "path";
|
||||
import { logger } from "../logger";
|
||||
import { TorBoxClient } from "./torbox";
|
||||
import axios from "axios";
|
||||
|
||||
export class DownloadManager {
|
||||
private static downloadingGameId: number | null = null;
|
||||
@ -262,11 +263,16 @@ export class DownloadManager {
|
||||
case Downloader.PixelDrain: {
|
||||
const id = game!.uri!.split("/").pop();
|
||||
|
||||
const name = await axios
|
||||
.get(`https://pixeldrain.com/api/file/${id}/info`)
|
||||
.then((res) => res.data.name as string);
|
||||
|
||||
return {
|
||||
action: "start",
|
||||
game_id: game.id,
|
||||
url: `https://pixeldrain.com/api/file/${id}?download`,
|
||||
save_path: game.downloadPath!,
|
||||
out: name,
|
||||
};
|
||||
}
|
||||
case Downloader.Qiwi: {
|
||||
@ -297,15 +303,16 @@ export class DownloadManager {
|
||||
};
|
||||
}
|
||||
case Downloader.TorBox: {
|
||||
const downloadUrl = await TorBoxClient.getDownloadUrl(game.uri!);
|
||||
console.log(downloadUrl);
|
||||
const { name, url } = await TorBoxClient.getDownloadInfo(game.uri!);
|
||||
console.log(url, name);
|
||||
|
||||
if (!downloadUrl) return;
|
||||
if (!url) return;
|
||||
return {
|
||||
action: "start",
|
||||
game_id: game.id,
|
||||
url: downloadUrl,
|
||||
url,
|
||||
save_path: game.downloadPath!,
|
||||
out: name,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ export class TorBoxClient {
|
||||
return response.data.data;
|
||||
}
|
||||
|
||||
static async getTorrentId(magnetUri: string) {
|
||||
static async getTorrentIdAndName(magnetUri: string) {
|
||||
const userTorrents = await this.getAllTorrentsFromUser();
|
||||
|
||||
const { infoHash } = await parseTorrent(magnetUri);
|
||||
@ -82,14 +82,15 @@ export class TorBoxClient {
|
||||
(userTorrent) => userTorrent.hash === infoHash
|
||||
);
|
||||
|
||||
if (userTorrent) return userTorrent.id;
|
||||
if (userTorrent) return { id: userTorrent.id, name: userTorrent.name };
|
||||
|
||||
const torrent = await this.addMagnet(magnetUri);
|
||||
return torrent.torrent_id;
|
||||
return { id: torrent.torrent_id, name: torrent.name };
|
||||
}
|
||||
|
||||
static async getDownloadUrl(uri: string) {
|
||||
const id = await this.getTorrentId(uri);
|
||||
return this.requestLink(id);
|
||||
static async getDownloadInfo(uri: string) {
|
||||
const { id, name } = await this.getTorrentIdAndName(uri);
|
||||
const url = await this.requestLink(id);
|
||||
return { url, name: `${name}.zip` };
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ export interface TorBoxAddTorrentRequest {
|
||||
torrent_id: number;
|
||||
name: string;
|
||||
hash: string;
|
||||
size: number;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user