chore: removing rust rpc

This commit is contained in:
Chubby Granny Chaser
2025-04-15 15:41:08 +01:00
parent f2efbfba3a
commit c090a27ff3
34 changed files with 164 additions and 3218 deletions

View File

@@ -1,94 +1,48 @@
import os
import subprocess
import json
import aria2p
class HttpDownloader:
def __init__(self, hydra_httpdl_bin: str):
self.hydra_exe = hydra_httpdl_bin
self.process = None
self.last_status = None
def start_download(self, url: str, save_path: str, header: str = None, allow_multiple_connections: bool = False, connections_limit: int = 1):
cmd = [self.hydra_exe]
cmd.append(url)
cmd.extend([
"--chunk-size", "10",
"--buffer-size", "16",
"--force-download",
"--log",
"--silent"
])
if header:
cmd.extend(["--header", header])
if allow_multiple_connections:
cmd.extend(["--connections", str(connections_limit)])
else:
cmd.extend(["--connections", "1"])
print(f"running hydra-httpdl: {' '.join(cmd)}")
try:
self.process = subprocess.Popen(
cmd,
cwd=save_path,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
def __init__(self):
self.download = None
self.aria2 = aria2p.API(
aria2p.Client(
host="http://localhost",
port=6800,
secret=""
)
except Exception as e:
print(f"error running hydra-httpdl: {e}")
return None
)
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 get_download_status(self):
if not self.process:
if self.download == None:
return None
try:
line = self.process.stdout.readline()
if line:
status = json.loads(line.strip())
self.last_status = status
elif self.last_status:
status = self.last_status
else:
return None
response = {
"status": "active",
"progress": status["progress"],
"downloadSpeed": status["speed_bps"],
"numPeers": 0,
"numSeeds": 0,
"bytesDownloaded": status["downloaded_bytes"],
"fileSize": status["total_bytes"],
"folderName": status["filename"]
}
if status["progress"] == 1:
response["status"] = "complete"
return response
except Exception as e:
print(f"error getting download status: {e}")
return None
def stop_download(self):
if self.process:
self.process.terminate()
self.process = None
self.last_status = None
def pause_download(self):
self.stop_download()
def cancel_download(self):
self.stop_download()
download = self.aria2.get_download(self.download.gid)
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

View File

@@ -13,7 +13,6 @@ http_port = sys.argv[2]
rpc_password = sys.argv[3]
start_download_payload = sys.argv[4]
start_seeding_payload = sys.argv[5]
hydra_httpdl_bin = sys.argv[6]
downloads = {}
# This can be streamed down from Node
@@ -33,10 +32,10 @@ if start_download_payload:
except Exception as e:
print("Error starting torrent download", e)
else:
http_downloader = HttpDownloader(hydra_httpdl_bin)
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'), initial_download.get('allow_multiple_connections', False), initial_download.get('connections_limit', 24))
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)
@@ -148,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('allow_multiple_connections', False), data.get('connections_limit', 24))
existing_downloader.start_download(url, data['save_path'], data.get('header'), data.get('out'))
else:
http_downloader = HttpDownloader(hydra_httpdl_bin)
http_downloader = HttpDownloader()
downloads[game_id] = http_downloader
http_downloader.start_download(url, data['save_path'], data.get('header'), data.get('allow_multiple_connections', False), data.get('connections_limit', 24))
http_downloader.start_download(url, data['save_path'], data.get('header'), data.get('out'))
downloading_game_id = game_id
@@ -183,4 +182,3 @@ def action():
if __name__ == "__main__":
app.run(host="0.0.0.0", port=int(http_port))