Files
SoftwareManager/core/downloading/aria2p_server.py
T
2025-09-21 02:16:17 +02:00

56 lines
1.0 KiB
Python

import aria2p
import os
import subprocess
import time
def run_aria2p():
global aria2
aria2 = aria2p.API(
aria2p.Client(
host="http://localhost",
port=6800,
secret=""
)
)
return aria2
t = 4 # default value
def set_threads(threads):
global t
t = threads
def aria2server():
downloads_dir = os.path.join("Library")
cmd = [
"aria2c",
"--enable-rpc",
"--disable-ipv6", # added this since it caused problems with vpns
"--rpc-listen-all",
"--rpc-listen-port=6800",
f"--dir={downloads_dir}",
"-x", str(t),
"-s", str(t),
]
aria2server = subprocess.Popen(cmd)
return aria2server
def dlprogress():
try:
download2 = aria2.get_downloads()
if download2:
for download in download2:
progress = download.progress_string(0)
progress_int = int(progress.strip('%'))
return progress_int
return 0
except:
return 0