Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,45 @@
|
|
1 |
import yt_dlp
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
5 |
ydl_opts = {
|
6 |
'format': 'bestaudio/best',
|
7 |
'postprocessors': [{
|
8 |
'key': 'FFmpegExtractAudio',
|
9 |
-
'preferredcodec':
|
10 |
-
'preferredquality': '192',
|
11 |
}],
|
12 |
-
'outtmpl':
|
13 |
}
|
14 |
|
15 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
16 |
-
ydl.download([
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
|
21 |
-
with gr.Blocks() as demo:
|
22 |
-
url = gr.Textbox(label="url video")
|
23 |
-
custom_name = gr.Textbox(label="custom_name")
|
24 |
-
output = gr.Audio(label="output")
|
25 |
-
download_youtube_wav_btn = gr.Button("Greet")
|
26 |
-
download_youtube_wav_btn.click(fn=download_youtube_wav, inputs=url, custom_name, outputs=output)
|
27 |
|
28 |
-
demo.launch()
|
|
|
1 |
import yt_dlp
|
2 |
import gradio as gr
|
3 |
|
4 |
+
import os
|
5 |
+
import yt_dlp
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
def downloader(video_url, save_folder, audio_format, audio_name):
|
9 |
+
save_path = os.path.join(save_folder, audio_name)
|
10 |
ydl_opts = {
|
11 |
'format': 'bestaudio/best',
|
12 |
'postprocessors': [{
|
13 |
'key': 'FFmpegExtractAudio',
|
14 |
+
'preferredcodec': audio_format,
|
|
|
15 |
}],
|
16 |
+
'outtmpl': save_path,
|
17 |
}
|
18 |
|
19 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
20 |
+
ydl.download([video_url])
|
21 |
+
return f"Audio downloaded successfully to {save_path}"
|
22 |
+
|
23 |
+
inputs = [
|
24 |
+
gr.inputs.Textbox(label="YouTube video link", default="https://youtu.be/L3P0LgwuPPo?si=3dLDS6WIGM2Lk9gf"),
|
25 |
+
gr.inputs.Textbox(label="Audio name", default="Harenchi"),
|
26 |
+
gr.inputs.Textbox(label="Output path for downloaded audio files", default="/content/drive/MyDrive/Separar"),
|
27 |
+
gr.inputs.Radio(["wav", "flac", "mp3"], label="Select the output format", default="wav")
|
28 |
+
]
|
29 |
+
|
30 |
+
output = gr.outputs.Textbox(label="Output")
|
31 |
+
|
32 |
+
title = "YouTube Audio Downloader"
|
33 |
+
description = "Download audio from YouTube videos"
|
34 |
+
|
35 |
+
gr.Interface(
|
36 |
+
fn=downloader,
|
37 |
+
inputs=inputs,
|
38 |
+
outputs=output,
|
39 |
+
title=title,
|
40 |
+
description=description,
|
41 |
+
theme="light"
|
42 |
+
).launch()
|
43 |
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
|