Spaces:
Running
Running
Update src/main.py
Browse files- 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': '
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
70 |
}
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
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 |
|