Blane187 commited on
Commit
e8ecf5d
·
verified ·
1 Parent(s): 1d4aba9

Update src/main.py

Browse files
Files changed (1) hide show
  1. src/main.py +17 -13
src/main.py CHANGED
@@ -62,20 +62,24 @@ def get_youtube_video_id(url, ignore_playlist=True): # this code unused here!
62
 
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
 
 
62
 
63
  def yt_download(link):
64
  ydl_opts = {
65
+ 'format': 'bestaudio/best',
66
+ 'outtmpl': 'ytdl/%(title)s.%(ext)s',
67
+ 'postprocessors': [{
68
+ 'key': 'FFmpegExtractAudio',
69
+ 'preferredcodec': 'wav',
70
+ 'preferredquality': '192',
71
+ }],
72
  }
73
+
74
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
75
+ info_dict = ydl.extract_info(url, download=True)
76
+ download_path = ydl.prepare_filename(info_dict).rsplit('.', 1)[0] + '.wav'
77
+ sample_rate, audio_data = read(file_path)
78
+ audio_array = np.asarray(audio_data, dtype=np.int16)
79
+
80
+ return download_path
81
+
82
+
83
 
84
 
85