Spaces:
Sleeping
Sleeping
pierreguillou
commited on
Commit
·
87dc9c9
1
Parent(s):
eb94b9d
Update app.py
Browse files
app.py
CHANGED
@@ -13,20 +13,16 @@ def cleanString(string):
|
|
13 |
def download_audio(url):
|
14 |
path_to_folder_audio_mp3 = "./audio/"
|
15 |
ydl_opts = {
|
16 |
-
# 'format': 'bestaudio/best',
|
17 |
'format': 'm4a/bestaudio/best',
|
18 |
-
# 'outtmpl': '%(id)s.%(ext)s',
|
19 |
'outtmpl': f'{path_to_folder_audio_mp3}%(title)s',
|
20 |
'postprocessors': [{
|
21 |
'key': 'FFmpegExtractAudio',
|
22 |
'preferredcodec': 'mp3',
|
23 |
-
# 'preferredquality': '192',
|
24 |
}]
|
25 |
}
|
26 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
27 |
info_dict = ydl.extract_info(url, download=True)
|
28 |
video_title = info_dict['title']
|
29 |
-
# ydl.download([video_link])
|
30 |
|
31 |
# Rename the audio file
|
32 |
local_link = video_title + ".mp3"
|
@@ -37,17 +33,10 @@ def download_audio(url):
|
|
37 |
|
38 |
return path_to_folder_audio_mp3 + new_local_link
|
39 |
|
40 |
-
#
|
41 |
-
# video_url = download_video(url)
|
42 |
-
# video = mp.VideoFileClip(video_url)
|
43 |
-
# audio = video.audio
|
44 |
-
# audio_file = "output_audio.mp3"
|
45 |
-
# audio.write_audiofile(audio_file)
|
46 |
-
# return audio_file
|
47 |
-
|
48 |
iface = gr.Interface(fn=download_audio,
|
49 |
inputs=gr.Textbox(label="YouTube Video URL"),
|
50 |
-
outputs=gr.
|
51 |
allow_flagging="never"
|
52 |
)
|
53 |
-
iface.launch(
|
|
|
13 |
def download_audio(url):
|
14 |
path_to_folder_audio_mp3 = "./audio/"
|
15 |
ydl_opts = {
|
|
|
16 |
'format': 'm4a/bestaudio/best',
|
|
|
17 |
'outtmpl': f'{path_to_folder_audio_mp3}%(title)s',
|
18 |
'postprocessors': [{
|
19 |
'key': 'FFmpegExtractAudio',
|
20 |
'preferredcodec': 'mp3',
|
|
|
21 |
}]
|
22 |
}
|
23 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
24 |
info_dict = ydl.extract_info(url, download=True)
|
25 |
video_title = info_dict['title']
|
|
|
26 |
|
27 |
# Rename the audio file
|
28 |
local_link = video_title + ".mp3"
|
|
|
33 |
|
34 |
return path_to_folder_audio_mp3 + new_local_link
|
35 |
|
36 |
+
# Gradio interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
iface = gr.Interface(fn=download_audio,
|
38 |
inputs=gr.Textbox(label="YouTube Video URL"),
|
39 |
+
outputs=gr.Audio(label="Output Audio", type="filepath"),
|
40 |
allow_flagging="never"
|
41 |
)
|
42 |
+
iface.launch()
|