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