Shahadbal commited on
Commit
544d324
·
verified ·
1 Parent(s): 4fe9b45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -69,9 +69,14 @@ def download_audio_from_youtube(youtube_url, output_path="downloaded_audio.mp3")
69
  }
70
 
71
  try:
72
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
73
- ydl.download([youtube_url])
74
- os.rename('temp_audio.mp3', output_path)
 
 
 
 
 
75
  return output_path
76
  except Exception as e:
77
  return f"Error downloading audio: {e}"
 
69
  }
70
 
71
  try:
72
+ command = [
73
+ "yt-dlp",
74
+ "-x", # extract audio only
75
+ "--audio-format", "mp3", # specify mp3 format
76
+ "-o", output_path, # specify output path
77
+ youtube_url # YouTube URL
78
+ ]
79
+ subprocess.run(command, check=True, capture_output=True)
80
  return output_path
81
  except Exception as e:
82
  return f"Error downloading audio: {e}"