Merge pull request #5 from DasPoschi/codex/add-integration-for-chatgpt.com-a56dpf
Retry downloads with next proxy on failure
This commit is contained in:
@@ -96,6 +96,7 @@ class Job:
|
|||||||
engine: str
|
engine: str
|
||||||
library: str
|
library: str
|
||||||
proxy: str
|
proxy: str
|
||||||
|
proxy_forced: bool
|
||||||
headers: List[str]
|
headers: List[str]
|
||||||
progress: float
|
progress: float
|
||||||
status: str
|
status: str
|
||||||
@@ -127,8 +128,7 @@ def pick_proxy(forced_proxy: str = "") -> str:
|
|||||||
global _rr_idx
|
global _rr_idx
|
||||||
if forced_proxy:
|
if forced_proxy:
|
||||||
return forced_proxy.strip() if proxy_is_usable(forced_proxy.strip()) else ""
|
return forced_proxy.strip() if proxy_is_usable(forced_proxy.strip()) else ""
|
||||||
with lock:
|
proxies = snapshot_proxies()
|
||||||
proxies = list(PROXIES)
|
|
||||||
if PROXY_MODE == "off" or not proxies:
|
if PROXY_MODE == "off" or not proxies:
|
||||||
return ""
|
return ""
|
||||||
if PROXY_MODE == "random":
|
if PROXY_MODE == "random":
|
||||||
@@ -221,6 +221,11 @@ def refresh_proxies() -> None:
|
|||||||
PROXIES = updated
|
PROXIES = updated
|
||||||
|
|
||||||
|
|
||||||
|
def snapshot_proxies() -> List[str]:
|
||||||
|
with lock:
|
||||||
|
return list(PROXIES)
|
||||||
|
|
||||||
|
|
||||||
def proxy_refresh_loop(interval_seconds: int = 12 * 60 * 60) -> None:
|
def proxy_refresh_loop(interval_seconds: int = 12 * 60 * 60) -> None:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
@@ -307,7 +312,6 @@ def run_aria2(url: str, out_dir: str, proxy: str, progress_cb, headers: List[str
|
|||||||
raise subprocess.CalledProcessError(ret, cmd)
|
raise subprocess.CalledProcessError(ret, cmd)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def md5_file(path: str) -> str:
|
def md5_file(path: str) -> str:
|
||||||
h = hashlib.md5()
|
h = hashlib.md5()
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
@@ -415,6 +419,8 @@ def worker(jobid: str):
|
|||||||
engine = pick_engine(job.url, job.engine)
|
engine = pick_engine(job.url, job.engine)
|
||||||
proxy = job.proxy
|
proxy = job.proxy
|
||||||
headers = job.headers
|
headers = job.headers
|
||||||
|
proxy_forced = job.proxy_forced
|
||||||
|
proxy_candidates = []
|
||||||
|
|
||||||
with lock:
|
with lock:
|
||||||
header_note = f"Headers={len(headers)}" if headers else "Headers=none"
|
header_note = f"Headers={len(headers)}" if headers else "Headers=none"
|
||||||
@@ -428,17 +434,33 @@ def worker(jobid: str):
|
|||||||
|
|
||||||
if engine == "ytdlp":
|
if engine == "ytdlp":
|
||||||
run_ytdlp(job.url, OUTPUT_DIR, YTDLP_FORMAT, proxy, update_progress)
|
run_ytdlp(job.url, OUTPUT_DIR, YTDLP_FORMAT, proxy, update_progress)
|
||||||
elif engine == "hoster":
|
|
||||||
run_aria2(job.url, OUTPUT_DIR, proxy, update_progress, headers=headers)
|
|
||||||
else:
|
else:
|
||||||
run_aria2(job.url, OUTPUT_DIR, proxy, update_progress)
|
if proxy:
|
||||||
|
if proxy_forced:
|
||||||
|
proxy_candidates = [proxy]
|
||||||
|
else:
|
||||||
|
proxy_list = snapshot_proxies()
|
||||||
|
proxy_candidates = [proxy] + [p for p in proxy_list if p != proxy]
|
||||||
|
else:
|
||||||
|
proxy_candidates = [""]
|
||||||
|
|
||||||
if engine == "ytdlp":
|
for idx, candidate in enumerate(proxy_candidates):
|
||||||
run_ytdlp(job.url, OUTPUT_DIR, YTDLP_FORMAT, proxy)
|
try:
|
||||||
elif engine == "hoster":
|
if engine == "hoster":
|
||||||
run_aria2(job.url, OUTPUT_DIR, proxy, headers=headers)
|
run_aria2(job.url, OUTPUT_DIR, candidate, update_progress, headers=headers)
|
||||||
else:
|
else:
|
||||||
run_aria2(job.url, OUTPUT_DIR, proxy)
|
run_aria2(job.url, OUTPUT_DIR, candidate, update_progress)
|
||||||
|
break
|
||||||
|
except subprocess.CalledProcessError as exc:
|
||||||
|
if idx == len(proxy_candidates) - 1:
|
||||||
|
raise
|
||||||
|
with lock:
|
||||||
|
job.message = f"Proxy failed, trying next ({idx + 1}/{len(proxy_candidates) - 1})"
|
||||||
|
except Exception as exc:
|
||||||
|
if idx == len(proxy_candidates) - 1:
|
||||||
|
raise
|
||||||
|
with lock:
|
||||||
|
job.message = f"Proxy failed, trying next ({idx + 1}/{len(proxy_candidates) - 1})"
|
||||||
|
|
||||||
new_files = list_output_files(before)
|
new_files = list_output_files(before)
|
||||||
if not new_files:
|
if not new_files:
|
||||||
@@ -596,11 +618,6 @@ def render_downloads(error: str = "") -> str:
|
|||||||
}}
|
}}
|
||||||
setInterval(refreshProgress, 2000);
|
setInterval(refreshProgress, 2000);
|
||||||
</script>
|
</script>
|
||||||
<thead><tr><th>JobID</th><th>URL</th><th>Engine</th><th>Library</th><th>Proxy</th><th>Status</th></tr></thead>
|
|
||||||
<tbody>
|
|
||||||
{rows if rows else "<tr><td colspan='6'><em>No jobs yet.</em></td></tr>"}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</body></html>
|
</body></html>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -653,6 +670,7 @@ def submit(
|
|||||||
engine=engine,
|
engine=engine,
|
||||||
library=library,
|
library=library,
|
||||||
proxy=chosen_proxy,
|
proxy=chosen_proxy,
|
||||||
|
proxy_forced=bool(proxy.strip()),
|
||||||
headers=header_lines,
|
headers=header_lines,
|
||||||
progress=0.0,
|
progress=0.0,
|
||||||
status="queued",
|
status="queued",
|
||||||
|
|||||||
Reference in New Issue
Block a user