Blane187 commited on
Commit
61a7f45
·
verified ·
1 Parent(s): e6b8f03
Files changed (1) hide show
  1. src/main.py +10 -9
src/main.py CHANGED
@@ -63,21 +63,22 @@ def get_youtube_video_id(url, ignore_playlist=True): # this code unused here!
63
  def yt_download(link):
64
  ydl_opts = {
65
  'format': 'bestaudio',
66
- 'outtmpl': '%(title)s',
67
- 'nocheckcertificate': True,
68
- 'ignoreerrors': True,
69
- 'no_warnings': True,
70
- 'quiet': True,
71
  'extractaudio': True,
72
  'postprocessors': [{'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3'}],
73
  }
74
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
75
- result = ydl.extract_info(link, download=True)
76
- download_path = ydl.prepare_filename(result, outtmpl='%(title)s.mp3')
77
-
 
 
 
78
  return download_path
79
 
80
 
 
81
  def raise_exception(error_msg, is_webui):
82
  if is_webui:
83
  raise gr.Error(error_msg)
 
63
  def yt_download(link):
64
  ydl_opts = {
65
  'format': 'bestaudio',
66
+ 'outtmpl': '%(title)s.%(ext)s',
67
+
 
 
 
68
  'extractaudio': True,
69
  'postprocessors': [{'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3'}],
70
  }
71
+ try:
72
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
73
+ result = ydl.extract_info(link, download=True)
74
+ download_path = ydl.prepare_filename(result, outtmpl='%(title)s.mp3')
75
+ except Exception as e:
76
+ raise Exception(f"Error downloading video: {e}")
77
+
78
  return download_path
79
 
80
 
81
+
82
  def raise_exception(error_msg, is_webui):
83
  if is_webui:
84
  raise gr.Error(error_msg)