Spaces:
Runtime error
Runtime error
Update run.py
Browse files
run.py
CHANGED
@@ -1,43 +1,39 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import
|
4 |
-
from IPython.display import Audio
|
5 |
|
6 |
-
def get_video_title(url):
|
7 |
-
# 使用 yt-dlp 获取视频标题
|
8 |
-
result = subprocess.run(["yt-dlp", "--get-title", url], capture_output=True, text=True)
|
9 |
-
if result.returncode == 0:
|
10 |
-
return result.stdout.strip()
|
11 |
-
else:
|
12 |
-
return "Unknown Video"
|
13 |
|
14 |
-
def
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
return filename
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
gr.Dropdown(value="wav", label="format")
|
38 |
-
],
|
39 |
-
outputs=gr.Audio(label="Download the file!"),
|
40 |
-
description="<div style='font-size:30px; text-align:center;'>YouTube wav downloader</div>"
|
41 |
-
)
|
42 |
-
|
43 |
-
app.launch(debug=True, share=True)
|
|
|
1 |
import gradio as gr
|
2 |
+
import yt_dlp
|
3 |
+
import ffmpeg
|
|
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
def download_audio(url):
|
7 |
+
ydl_opts = {
|
8 |
+
'format': 'bestaudio/best',
|
9 |
+
'postprocessors': [{
|
10 |
+
'key': 'FFmpegExtractAudio',
|
11 |
+
'preferredcodec': 'wav',
|
12 |
+
'preferredquality': '192',
|
13 |
+
}],
|
14 |
+
'outtmpl': '%(title)s.%(ext)s',
|
15 |
+
}
|
16 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
17 |
+
ydl.download([url])
|
18 |
+
return "audio downloaded as '%(title)s.wav'"
|
19 |
|
|
|
20 |
|
21 |
+
with gr.Blocks() as demo:
|
22 |
+
used_letters_var = gr.State([])
|
23 |
+
with gr.Column():
|
24 |
+
gr.Markdown("# YT_DLP GRADIO DEMO")
|
25 |
+
gr.Markdown("Please press like button to support me :]")
|
26 |
+
with gr.Row() as row:
|
27 |
+
with gr.Column():
|
28 |
+
url = gr.Textbox(label="URL INPUT")
|
29 |
+
|
30 |
+
with gr.Column():
|
31 |
+
btn = gr.Button("download!")
|
32 |
+
outputs = gr.Audio(label="outputs")
|
33 |
|
34 |
+
btn.click(
|
35 |
+
download_audio,
|
36 |
+
[url],
|
37 |
+
[outputs]
|
38 |
+
)
|
39 |
+
demo.launch(debug=True, share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|