Improve YouTube download with better error handling and auth
Browse files
app.py
CHANGED
|
@@ -280,13 +280,29 @@ def download_youtube(url: str) -> tuple:
|
|
| 280 |
'preferredcodec': 'wav',
|
| 281 |
}],
|
| 282 |
'quiet': True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 285 |
info = ydl.extract_info(url, download=True)
|
| 286 |
title = info.get('title', 'Unknown')
|
| 287 |
return str(output_path), title
|
| 288 |
except Exception as e:
|
| 289 |
-
|
|
|
|
|
|
|
|
|
|
| 290 |
|
| 291 |
@spaces.GPU(duration=120)
|
| 292 |
def separate_stems(audio_path: str, progress=None) -> dict:
|
|
|
|
| 280 |
'preferredcodec': 'wav',
|
| 281 |
}],
|
| 282 |
'quiet': True,
|
| 283 |
+
'no_warnings': True,
|
| 284 |
+
'socket_timeout': 60,
|
| 285 |
+
'retries': 5,
|
| 286 |
+
'extractor_args': {
|
| 287 |
+
'youtube': {
|
| 288 |
+
'player_client': ['web', 'android', 'ios'],
|
| 289 |
+
}
|
| 290 |
+
},
|
| 291 |
}
|
| 292 |
+
|
| 293 |
+
# Try with browser cookies on local, skip on HF Space
|
| 294 |
+
if not IS_HF_SPACE:
|
| 295 |
+
ydl_opts['cookiesfrombrowser'] = ('chrome',)
|
| 296 |
+
|
| 297 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 298 |
info = ydl.extract_info(url, download=True)
|
| 299 |
title = info.get('title', 'Unknown')
|
| 300 |
return str(output_path), title
|
| 301 |
except Exception as e:
|
| 302 |
+
error_msg = str(e)
|
| 303 |
+
if 'Sign in to confirm' in error_msg or 'bot' in error_msg.lower():
|
| 304 |
+
return None, "YouTube requires authentication. Please upload the audio file directly instead, or try a different video."
|
| 305 |
+
return None, error_msg
|
| 306 |
|
| 307 |
@spaces.GPU(duration=120)
|
| 308 |
def separate_stems(audio_path: str, progress=None) -> dict:
|