Spaces:
Runtime error
Runtime error
Update run.py
Browse files
run.py
CHANGED
@@ -1,44 +1,32 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import os
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
return result.stdout.strip()
|
9 |
-
else:
|
10 |
-
return "Unknown Video"
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
max_length = 50
|
15 |
-
truncated_title = title[:max_length].strip()
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
return filename
|
26 |
-
|
27 |
-
def play_audio(output_audio):
|
28 |
-
audio = AudioSegment.from_file(output_audio)
|
29 |
-
audio.export("output.wav", format="wav")
|
30 |
-
gr.Interface(fn=None, live=False, outputs="audio").play("output.wav")
|
31 |
-
|
32 |
-
app = gr.Interface(
|
33 |
-
theme='Hev832/EasyAndCool',
|
34 |
-
fn=play_audio,
|
35 |
-
inputs=[
|
36 |
-
gr.Textbox(label="YouTube video address", placeholder="Paste video link here..."),
|
37 |
-
gr.Textbox(label="File name", placeholder="Defaults to video title"),
|
38 |
-
gr.Dropdown(value="wav", label="Format")
|
39 |
-
],
|
40 |
-
outputs=None,
|
41 |
-
description="<div style='font-size:30px; text-align:center;'>YouTube Audio downloader</div>"
|
42 |
-
)
|
43 |
|
44 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
import yt_dlp
|
3 |
import os
|
4 |
|
5 |
+
def downloader(video_url, audio_format, audio_name):
|
6 |
+
save_path = os.path.join(audio_name)
|
7 |
+
ydl_opts = {
|
8 |
+
'format': 'bestaudio/best',
|
9 |
+
'postprocessors': [{
|
10 |
+
'key': 'FFmpegExtractAudio',
|
11 |
+
'preferredcodec': audio_format,
|
12 |
+
}],
|
13 |
+
'outtmpl': save_path,
|
14 |
+
}
|
15 |
|
16 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
17 |
+
ydl.download([video_url])
|
18 |
+
return save_path
|
|
|
|
|
|
|
19 |
|
20 |
+
with gr.Blocks() as demo:
|
21 |
+
gr.Markdown("# YouTube Audio Downloader")
|
|
|
|
|
22 |
|
23 |
+
video_url = gr.Textbox(label="YouTube video link")
|
24 |
+
audio_name = gr.Textbox(label="Audio name of YouTube audio")
|
25 |
+
audio_format = gr.Radio(["wav", "flac", "mp3"], label="Select the output format")
|
26 |
+
|
27 |
+
output = gr.Textbox(label="Output")
|
28 |
+
|
29 |
+
download_button = gr.Button("Download")
|
30 |
+
download_button.click(downloader, inputs=[video_url, audio_format, audio_name], outputs=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
demo.launch()
|