Spaces:
Sleeping
Sleeping
Devank Upadhyaya commited on
Commit ·
b6c5778
1
Parent(s): df7a9df
Bypass YouTube throttling on HF Spaces with android player client
Browse files
tools.py
CHANGED
|
@@ -146,7 +146,16 @@ def download_youtube_video(url: str, out_path: str) -> str:
|
|
| 146 |
last_error = ""
|
| 147 |
|
| 148 |
for fmt in format_options:
|
| 149 |
-
cmd = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
logger.debug(f"Trying yt-dlp format: {fmt}")
|
| 151 |
try:
|
| 152 |
result = subprocess.run(cmd, capture_output=True, text=True, timeout=25)
|
|
@@ -160,8 +169,16 @@ def download_youtube_video(url: str, out_path: str) -> str:
|
|
| 160 |
|
| 161 |
fallback_template = out_path.replace(".mp4", ".%(ext)s")
|
| 162 |
try:
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
except subprocess.TimeoutExpired as e:
|
| 166 |
logger.error(f"Fallback timeout: {e}")
|
| 167 |
|
|
|
|
| 146 |
last_error = ""
|
| 147 |
|
| 148 |
for fmt in format_options:
|
| 149 |
+
cmd = [
|
| 150 |
+
"yt-dlp",
|
| 151 |
+
"-f", fmt,
|
| 152 |
+
"--socket-timeout", "15",
|
| 153 |
+
"--no-playlist",
|
| 154 |
+
"--no-warnings",
|
| 155 |
+
"--extractor-args", "youtube:player_client=android",
|
| 156 |
+
"-o", out_path,
|
| 157 |
+
url
|
| 158 |
+
]
|
| 159 |
logger.debug(f"Trying yt-dlp format: {fmt}")
|
| 160 |
try:
|
| 161 |
result = subprocess.run(cmd, capture_output=True, text=True, timeout=25)
|
|
|
|
| 169 |
|
| 170 |
fallback_template = out_path.replace(".mp4", ".%(ext)s")
|
| 171 |
try:
|
| 172 |
+
cmd_fallback = [
|
| 173 |
+
"yt-dlp",
|
| 174 |
+
"--socket-timeout", "15",
|
| 175 |
+
"--no-playlist",
|
| 176 |
+
"--no-warnings",
|
| 177 |
+
"--extractor-args", "youtube:player_client=android",
|
| 178 |
+
"-o", fallback_template,
|
| 179 |
+
url
|
| 180 |
+
]
|
| 181 |
+
subprocess.run(cmd_fallback, capture_output=True, text=True, timeout=25)
|
| 182 |
except subprocess.TimeoutExpired as e:
|
| 183 |
logger.error(f"Fallback timeout: {e}")
|
| 184 |
|