Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -328,7 +328,7 @@ button:hover {
|
|
| 328 |
|
| 329 |
def download_audio(url, cookie_file):
|
| 330 |
ydl_opts = {
|
| 331 |
-
'format': 'bestaudio[ext=webm]/bestaudio[ext=m4a]/bestaudio/
|
| 332 |
'postprocessors': [{
|
| 333 |
'key': 'FFmpegExtractAudio',
|
| 334 |
'preferredcodec': 'wav',
|
|
@@ -350,7 +350,11 @@ def download_audio(url, cookie_file):
|
|
| 350 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 351 |
try:
|
| 352 |
info_dict = ydl.extract_info(url, download=True)
|
| 353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
if not os.path.exists(file_path):
|
| 355 |
return None, "Downloaded file not found", None
|
| 356 |
# Read the audio file for gr.Audio
|
|
@@ -358,10 +362,10 @@ def download_audio(url, cookie_file):
|
|
| 358 |
audio_data = (sample_rate, data)
|
| 359 |
return file_path, "Download successful", audio_data
|
| 360 |
except yt_dlp.utils.ExtractorError as e:
|
| 361 |
-
if "Sign in to confirm you’re not a bot" in str(e):
|
| 362 |
-
return None, "Authentication failed. Please upload updated cookies from a logged-in browser session in the respective tab.", None
|
| 363 |
elif "HTTP Error 403: Forbidden" in str(e):
|
| 364 |
-
return None, "Download failed: HTTP Error 403. This format requires a GVS PO Token
|
| 365 |
return None, f"Download failed: {str(e)}", None
|
| 366 |
except Exception as e:
|
| 367 |
return None, f"Unexpected error: {str(e)}", None
|
|
|
|
| 328 |
|
| 329 |
def download_audio(url, cookie_file):
|
| 330 |
ydl_opts = {
|
| 331 |
+
'format': 'bestaudio[ext=webm]/bestaudio[ext=m4a]/bestaudio[ext=opus]/bestaudio[ext=aac]/bestaudio -video', # Prioritize audio-only formats, exclude video
|
| 332 |
'postprocessors': [{
|
| 333 |
'key': 'FFmpegExtractAudio',
|
| 334 |
'preferredcodec': 'wav',
|
|
|
|
| 350 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 351 |
try:
|
| 352 |
info_dict = ydl.extract_info(url, download=True)
|
| 353 |
+
# Adjust file path for multiple possible extensions
|
| 354 |
+
base_file_path = ydl.prepare_filename(info_dict)
|
| 355 |
+
file_path = base_file_path
|
| 356 |
+
for ext in ['.webm', '.m4a', '.opus', '.aac']:
|
| 357 |
+
file_path = file_path.replace(ext, '.wav')
|
| 358 |
if not os.path.exists(file_path):
|
| 359 |
return None, "Downloaded file not found", None
|
| 360 |
# Read the audio file for gr.Audio
|
|
|
|
| 362 |
audio_data = (sample_rate, data)
|
| 363 |
return file_path, "Download successful", audio_data
|
| 364 |
except yt_dlp.utils.ExtractorError as e:
|
| 365 |
+
if "Sign in to confirm you’re not a bot" in str(e) or "The provided YouTube account cookies are no longer valid" in str(e):
|
| 366 |
+
return None, "Authentication failed. Please upload updated cookies from a logged-in browser session in the respective tab. See https://github.com/yt-dlp/yt-dlp/wiki/Extractors#exporting-youtube-cookies for instructions.", None
|
| 367 |
elif "HTTP Error 403: Forbidden" in str(e):
|
| 368 |
+
return None, "Download failed: HTTP Error 403. This format requires a GVS PO Token, or the cookies are invalid. Please upload fresh cookies. See https://github.com/yt-dlp/yt-dlp/wiki/PO-Token-Guide for advanced troubleshooting.", None
|
| 369 |
return None, f"Download failed: {str(e)}", None
|
| 370 |
except Exception as e:
|
| 371 |
return None, f"Unexpected error: {str(e)}", None
|