Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,17 +25,13 @@ from yt_dlp import YoutubeDL
|
|
| 25 |
from yt_dlp import YoutubeDL
|
| 26 |
import os
|
| 27 |
|
| 28 |
-
import yt_dlp
|
| 29 |
-
|
| 30 |
-
import yt_dlp
|
| 31 |
-
|
| 32 |
import yt_dlp
|
| 33 |
import time
|
| 34 |
import random
|
| 35 |
|
| 36 |
def download_video(url, cookies_file=None):
|
| 37 |
"""
|
| 38 |
-
Downloads a video from YouTube with bot evasion techniques
|
| 39 |
"""
|
| 40 |
print("Simulating human-like download...")
|
| 41 |
|
|
@@ -52,20 +48,18 @@ def download_video(url, cookies_file=None):
|
|
| 52 |
|
| 53 |
# Modern browser headers
|
| 54 |
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
|
| 55 |
-
'
|
| 56 |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
| 57 |
'Accept-Language': 'en-US,en;q=0.5',
|
| 58 |
'Sec-Fetch-Mode': 'navigate',
|
| 59 |
},
|
| 60 |
|
| 61 |
-
# Cookie authentication
|
| 62 |
-
'cookiefile': cookies_file
|
| 63 |
-
|
| 64 |
-
#
|
| 65 |
-
'throttledratelimit': random.randint(500, 1000),
|
| 66 |
'retries': 3,
|
| 67 |
'fragment_retries': 5,
|
| 68 |
-
'skip_download': False,
|
| 69 |
}
|
| 70 |
|
| 71 |
try:
|
|
@@ -75,10 +69,12 @@ def download_video(url, cookies_file=None):
|
|
| 75 |
return filename
|
| 76 |
except Exception as e:
|
| 77 |
print(f"Error: {str(e)}")
|
| 78 |
-
|
| 79 |
|
|
|
|
| 80 |
url = "https://www.youtube.com/watch?v=uLVRZE8OAI4"
|
| 81 |
-
download_video(url)
|
|
|
|
| 82 |
|
| 83 |
|
| 84 |
|
|
|
|
| 25 |
from yt_dlp import YoutubeDL
|
| 26 |
import os
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
import yt_dlp
|
| 29 |
import time
|
| 30 |
import random
|
| 31 |
|
| 32 |
def download_video(url, cookies_file=None):
|
| 33 |
"""
|
| 34 |
+
Downloads a video from YouTube with basic bot evasion techniques.
|
| 35 |
"""
|
| 36 |
print("Simulating human-like download...")
|
| 37 |
|
|
|
|
| 48 |
|
| 49 |
# Modern browser headers
|
| 50 |
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
|
| 51 |
+
'http_headers': {
|
| 52 |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
| 53 |
'Accept-Language': 'en-US,en;q=0.5',
|
| 54 |
'Sec-Fetch-Mode': 'navigate',
|
| 55 |
},
|
| 56 |
|
| 57 |
+
# Cookie authentication if provided
|
| 58 |
+
'cookiefile': cookies_file if cookies_file else None,
|
| 59 |
+
|
| 60 |
+
# Retry and fragment settings for robustness
|
|
|
|
| 61 |
'retries': 3,
|
| 62 |
'fragment_retries': 5,
|
|
|
|
| 63 |
}
|
| 64 |
|
| 65 |
try:
|
|
|
|
| 69 |
return filename
|
| 70 |
except Exception as e:
|
| 71 |
print(f"Error: {str(e)}")
|
| 72 |
+
return f"Download failed: {str(e)}"
|
| 73 |
|
| 74 |
+
# Example usage
|
| 75 |
url = "https://www.youtube.com/watch?v=uLVRZE8OAI4"
|
| 76 |
+
download_video(url)
|
| 77 |
+
|
| 78 |
|
| 79 |
|
| 80 |
|