Commit ·
b241b1e
1
Parent(s): 8579006
Final Fix: Bypass DNS check for Hugging Face proxies
Browse files
server.py
CHANGED
|
@@ -343,22 +343,25 @@ def download_video(youtube_url: str, max_retries: int = 3) -> Path:
|
|
| 343 |
for attempt in range(1, max_retries + 1):
|
| 344 |
print(f"[>>] Download attempt {attempt}/{max_retries} ...", flush=True)
|
| 345 |
|
| 346 |
-
# Quick DNS pre-check so we get a clear error instead of yt-dlp's wall of text
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
|
|
|
|
|
|
|
|
|
| 362 |
|
| 363 |
result = subprocess.run(cmd, capture_output=True)
|
| 364 |
|
|
|
|
| 343 |
for attempt in range(1, max_retries + 1):
|
| 344 |
print(f"[>>] Download attempt {attempt}/{max_retries} ...", flush=True)
|
| 345 |
|
| 346 |
+
# Quick DNS pre-check so we get a clear error instead of yt-dlp's wall of text.
|
| 347 |
+
# SKIP this check if a proxy is defined, as the proxy handles its own resolution.
|
| 348 |
+
if not YTDLP_PROXY:
|
| 349 |
+
try:
|
| 350 |
+
socket.setdefaulttimeout(10)
|
| 351 |
+
socket.getaddrinfo("www.youtube.com", 443, socket.AF_INET)
|
| 352 |
+
except socket.gaierror as dns_err:
|
| 353 |
+
last_err = (
|
| 354 |
+
f"DNS resolution failed for www.youtube.com: {dns_err}. "
|
| 355 |
+
"Hugging Face core spaces often block YouTube downloads. "
|
| 356 |
+
"FIX: (1) Use a GPU Space or (2) Add a proxy via YTDLP_PROXY env var."
|
| 357 |
+
)
|
| 358 |
+
print(f"[!] {last_err}", flush=True)
|
| 359 |
+
if attempt < max_retries:
|
| 360 |
+
time.sleep(2 ** attempt) # exponential backoff: 2, 4, 8 s
|
| 361 |
+
continue
|
| 362 |
+
raise RuntimeError(last_err)
|
| 363 |
+
else:
|
| 364 |
+
print(f"[>>] Skipping DNS pre-check because YTDLP_PROXY is set.", flush=True)
|
| 365 |
|
| 366 |
result = subprocess.run(cmd, capture_output=True)
|
| 367 |
|