Spaces:
Runtime error
Runtime error
Update run.py
Browse files
run.py
CHANGED
@@ -1,21 +1,33 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
19 |
|
20 |
with gr.Blocks() as demo:
|
21 |
used_letters_var = gr.State([])
|
@@ -25,13 +37,14 @@ with gr.Blocks() as demo:
|
|
25 |
with gr.Row() as row:
|
26 |
with gr.Column():
|
27 |
url = gr.Textbox(label="URL INPUT")
|
|
|
28 |
outputs = gr.Audio(label="outputs")
|
29 |
with gr.Column():
|
30 |
btn = gr.Button("download!")
|
31 |
|
32 |
|
33 |
btn.click(
|
34 |
-
|
35 |
[url],
|
36 |
[outputs]
|
37 |
)
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
import subprocess
|
4 |
|
5 |
+
def get_video_title(url):
|
6 |
+
|
7 |
+
result = subprocess.run(["yt-dlp", "--get-title", url], capture_output=True, text=True)
|
8 |
+
if result.returncode == 0:
|
9 |
+
return result.stdout.strip()
|
10 |
+
else:
|
11 |
+
return "Unknown Video"
|
12 |
+
|
13 |
+
def fetch(url, custom_name, ext):
|
14 |
+
title = get_video_title(url)
|
15 |
+
#
|
16 |
+
max_length = 50 #
|
17 |
+
truncated_title = title[:max_length].strip()
|
18 |
+
|
19 |
+
filename = f"{custom_name}.{ext}" if custom_name else f"{truncated_title}.{ext}"
|
20 |
+
opts = {
|
21 |
+
"mp3": ["-f", "ba", "-x", "--audio-format", "mp3"],
|
22 |
+
"wav": ["-f", "ba", "-x", "--audio-format", "wav"],
|
23 |
+
|
24 |
+
}[ext]
|
25 |
+
command = ["yt-dlp"] + opts + [url, "-o", filename]
|
26 |
+
subprocess.run(command)
|
27 |
+
|
28 |
+
return filename
|
29 |
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
with gr.Blocks() as demo:
|
33 |
used_letters_var = gr.State([])
|
|
|
37 |
with gr.Row() as row:
|
38 |
with gr.Column():
|
39 |
url = gr.Textbox(label="URL INPUT")
|
40 |
+
custom_name = gr.Textbox(label="Custom Name (defalut if you want!)")
|
41 |
outputs = gr.Audio(label="outputs")
|
42 |
with gr.Column():
|
43 |
btn = gr.Button("download!")
|
44 |
|
45 |
|
46 |
btn.click(
|
47 |
+
fetch,
|
48 |
[url],
|
49 |
[outputs]
|
50 |
)
|