Move unsupported proxy check to start of aria2c function

This commit is contained in:
rlaphoenix 2024-01-09 09:54:06 +00:00
parent 484338cf50
commit e54d4b4f41
1 changed files with 7 additions and 8 deletions

View File

@ -54,12 +54,19 @@ async def aria2c(
if not executable:
raise EnvironmentError("Aria2c executable not found...")
if proxy and proxy.lower().split(":")[0] != "http":
# HTTPS proxies are not supported by aria2(c).
# Proxy the proxy via pproxy to access it as an HTTP proxy.
async with start_pproxy(proxy) as pproxy_:
return await aria2c(uri, out, headers, cookies, pproxy_, silent, segmented, progress, *args)
arguments = [
"-c", # Continue downloading a partially downloaded file
"--remote-time", # Retrieve timestamp of the remote file from the and apply if available
"-x", "16", # The maximum number of connections to one server for each download
"-j", "16", # The maximum number of parallel downloads for every static (HTTP/FTP) URL
"-s", ("1" if segmented else "16"), # Download a file using N connections
"--all-proxy", proxy or "",
"--allow-overwrite=true",
"--auto-file-renaming=false",
"--retry-wait", "2", # Set the seconds to wait between retries.
@ -96,14 +103,6 @@ async def aria2c(
continue
arguments.extend(["--header", f"{header}: {value}"])
if proxy:
if proxy.lower().split(":")[0] != "http":
# HTTPS proxies are not supported by aria2(c).
# Proxy the proxy via pproxy to access it as an HTTP proxy.
async with start_pproxy(proxy) as pproxy_:
return await aria2c(uri, out, headers, cookies, pproxy_, silent, segmented, progress, *args)
arguments += ["--all-proxy", proxy]
try:
p = await asyncio.create_subprocess_exec(
executable,