Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import youtube_dl
|
3 |
+
|
4 |
+
def download_audio(youtube_url):
|
5 |
+
ydl_opts = {
|
6 |
+
'format': 'bestaudio/best',
|
7 |
+
'postprocessors': [{
|
8 |
+
'key': 'FFmpegExtractAudio',
|
9 |
+
'preferredcodec': 'mp3',
|
10 |
+
'preferredquality': '192',
|
11 |
+
}],
|
12 |
+
'outtmpl': 'downloads/%(title)s.%(ext)s',
|
13 |
+
}
|
14 |
+
|
15 |
+
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
16 |
+
info_dict = ydl.extract_info(youtube_url, download=True)
|
17 |
+
audio_file = ydl.prepare_filename(info_dict).replace('.webm', '.mp3').replace('.m4a', '.mp3')
|
18 |
+
|
19 |
+
return audio_file
|
20 |
+
|
21 |
+
with gr.Blocks() as demo:
|
22 |
+
with gr.Row():
|
23 |
+
url_input = gr.Textbox(label="YouTube URL")
|
24 |
+
download_button = gr.Button("Download Audio")
|
25 |
+
audio_output = gr.File(label="Downloaded Audio")
|
26 |
+
|
27 |
+
download_button.click(fn=download_audio, inputs=url_input, outputs=audio_output)
|
28 |
+
|
29 |
+
demo.launch()
|