ASesYusuf1 commited on
Commit
0d89795
·
verified ·
1 Parent(s): b956722

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -328,7 +328,7 @@ button:hover {
328
 
329
  def download_audio(url, cookie_file):
330
  ydl_opts = {
331
- 'format': 'bestaudio/best',
332
  'postprocessors': [{
333
  'key': 'FFmpegExtractAudio',
334
  'preferredcodec': 'wav',
@@ -350,7 +350,7 @@ 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
- file_path = ydl.prepare_filename(info_dict).replace('.webm', '.wav') # Adjust extension after extraction
354
  if not os.path.exists(file_path):
355
  return None, "Downloaded file not found", None
356
  # Read the audio file for gr.Audio
@@ -360,6 +360,8 @@ def download_audio(url, cookie_file):
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
  return None, f"Download failed: {str(e)}", None
364
  except Exception as e:
365
  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/best', # Prioritize audio-only formats
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
+ file_path = ydl.prepare_filename(info_dict).replace('.webm', '.wav').replace('.m4a', '.wav') # Adjust extension after extraction
354
  if not os.path.exists(file_path):
355
  return None, "Downloaded file not found", None
356
  # Read the audio file for gr.Audio
 
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. Try uploading fresh cookies or using a different URL. See https://github.com/yt-dlp/yt-dlp/wiki/PO-Token-Guide for more info.", None
365
  return None, f"Download failed: {str(e)}", None
366
  except Exception as e:
367
  return None, f"Unexpected error: {str(e)}", None