mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: fixing real debrid download
This commit is contained in:
parent
fffea84ef7
commit
68b361e605
28 changed files with 241 additions and 185 deletions
|
@ -3,19 +3,19 @@ from http.server import HTTPServer, BaseHTTPRequestHandler
|
|||
import json
|
||||
import urllib.parse
|
||||
import psutil
|
||||
from downloader import Downloader
|
||||
from torrent_downloader import TorrentDownloader
|
||||
|
||||
torrent_port = sys.argv[1]
|
||||
http_port = sys.argv[2]
|
||||
rpc_password = sys.argv[3]
|
||||
start_download_payload = sys.argv[4]
|
||||
|
||||
downloader = None
|
||||
torrent_downloader = None
|
||||
|
||||
if start_download_payload:
|
||||
initial_download = json.loads(urllib.parse.unquote(start_download_payload))
|
||||
downloader = Downloader(torrent_port)
|
||||
downloader.start_download(initial_download['game_id'], initial_download['magnet'], initial_download['save_path'])
|
||||
torrent_downloader = TorrentDownloader(torrent_port)
|
||||
torrent_downloader.start_download(initial_download['game_id'], initial_download['magnet'], initial_download['save_path'])
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
rpc_password_header = 'x-hydra-rpc-password'
|
||||
|
@ -31,7 +31,7 @@ class Handler(BaseHTTPRequestHandler):
|
|||
self.send_header("Content-type", "application/json")
|
||||
self.end_headers()
|
||||
|
||||
status = downloader.get_download_status()
|
||||
status = torrent_downloader.get_download_status()
|
||||
|
||||
self.wfile.write(json.dumps(status).encode('utf-8'))
|
||||
|
||||
|
@ -54,7 +54,7 @@ class Handler(BaseHTTPRequestHandler):
|
|||
self.wfile.write(json.dumps(process_list).encode('utf-8'))
|
||||
|
||||
def do_POST(self):
|
||||
global downloader
|
||||
global torrent_downloader
|
||||
|
||||
if self.path == "/action":
|
||||
if self.headers.get(self.rpc_password_header) != rpc_password:
|
||||
|
@ -66,18 +66,18 @@ class Handler(BaseHTTPRequestHandler):
|
|||
post_data = self.rfile.read(content_length)
|
||||
data = json.loads(post_data.decode('utf-8'))
|
||||
|
||||
if downloader is None:
|
||||
downloader = Downloader(torrent_port)
|
||||
if torrent_downloader is None:
|
||||
torrent_downloader = TorrentDownloader(torrent_port)
|
||||
|
||||
if data['action'] == 'start':
|
||||
downloader.start_download(data['game_id'], data['magnet'], data['save_path'])
|
||||
torrent_downloader.start_download(data['game_id'], data['magnet'], data['save_path'])
|
||||
elif data['action'] == 'pause':
|
||||
downloader.pause_download(data['game_id'])
|
||||
torrent_downloader.pause_download(data['game_id'])
|
||||
elif data['action'] == 'cancel':
|
||||
downloader.cancel_download(data['game_id'])
|
||||
torrent_downloader.cancel_download(data['game_id'])
|
||||
elif data['action'] == 'kill-torrent':
|
||||
downloader.abort_session()
|
||||
downloader = None
|
||||
torrent_downloader.abort_session()
|
||||
torrent_downloader = None
|
||||
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue