Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -314,7 +314,6 @@ import random
|
|
314 |
from datetime import datetime
|
315 |
import json
|
316 |
import requests
|
317 |
-
from fake_useragent import UserAgent
|
318 |
import http.cookiejar as cookielib
|
319 |
|
320 |
# Set page config
|
@@ -329,6 +328,15 @@ class Config:
|
|
329 |
MAX_RETRIES = 5
|
330 |
RETRY_DELAYS = [3, 5, 10, 15, 30] # Progressive delays in seconds
|
331 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
332 |
HEADERS_POOL = [
|
333 |
{
|
334 |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
@@ -356,9 +364,8 @@ class SessionManager:
|
|
356 |
|
357 |
@staticmethod
|
358 |
def get_random_headers():
|
359 |
-
ua = UserAgent()
|
360 |
headers = random.choice(Config.HEADERS_POOL).copy()
|
361 |
-
headers['User-Agent'] =
|
362 |
return headers
|
363 |
|
364 |
@staticmethod
|
@@ -384,7 +391,6 @@ def get_download_options(session_headers=None):
|
|
384 |
'retries': Config.MAX_RETRIES,
|
385 |
'file_access_retries': 3,
|
386 |
'fragment_retries': 3,
|
387 |
-
'retry_sleep_functions': {'http': lambda n: random.uniform(1, 5) * n},
|
388 |
'skip_unavailable_fragments': True,
|
389 |
'abort_on_unavailable_fragment': False,
|
390 |
}
|
@@ -416,14 +422,6 @@ def download_with_retry(url, progress_callback):
|
|
416 |
|
417 |
ydl_opts['progress_hooks'] = [progress_hook]
|
418 |
|
419 |
-
# Pre-check video availability
|
420 |
-
with yt_dlp.YoutubeDL({'quiet': True}) as ydl:
|
421 |
-
try:
|
422 |
-
ydl.extract_info(url, download=False)
|
423 |
-
except Exception as e:
|
424 |
-
if "This video is not available" in str(e):
|
425 |
-
return None, "Video is not available. It might be private or deleted."
|
426 |
-
|
427 |
# Actual download
|
428 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
429 |
info = ydl.extract_info(url, download=True)
|
|
|
314 |
from datetime import datetime
|
315 |
import json
|
316 |
import requests
|
|
|
317 |
import http.cookiejar as cookielib
|
318 |
|
319 |
# Set page config
|
|
|
328 |
MAX_RETRIES = 5
|
329 |
RETRY_DELAYS = [3, 5, 10, 15, 30] # Progressive delays in seconds
|
330 |
|
331 |
+
# 미리 정의된 User-Agent 목록
|
332 |
+
USER_AGENTS = [
|
333 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
334 |
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15',
|
335 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0',
|
336 |
+
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
337 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Edge/120.0.0.0 Safari/537.36'
|
338 |
+
]
|
339 |
+
|
340 |
HEADERS_POOL = [
|
341 |
{
|
342 |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
|
|
364 |
|
365 |
@staticmethod
|
366 |
def get_random_headers():
|
|
|
367 |
headers = random.choice(Config.HEADERS_POOL).copy()
|
368 |
+
headers['User-Agent'] = random.choice(Config.USER_AGENTS)
|
369 |
return headers
|
370 |
|
371 |
@staticmethod
|
|
|
391 |
'retries': Config.MAX_RETRIES,
|
392 |
'file_access_retries': 3,
|
393 |
'fragment_retries': 3,
|
|
|
394 |
'skip_unavailable_fragments': True,
|
395 |
'abort_on_unavailable_fragment': False,
|
396 |
}
|
|
|
422 |
|
423 |
ydl_opts['progress_hooks'] = [progress_hook]
|
424 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
# Actual download
|
426 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
427 |
info = ydl.extract_info(url, download=True)
|