Spaces:
Runtime error
Runtime error
File size: 1,390 Bytes
f7b3397 da8f353 1d6256c da8f353 f7b3397 6383b52 3686862 6383b52 da8f353 5bfebf5 6383b52 5bfebf5 3df3584 6383b52 da8f353 6383b52 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import gradio as gr
import os
import subprocess
def get_video_title(url):
result = subprocess.run(["yt-dlp", "--get-title", url], capture_output=True, text=True)
if result.returncode == 0:
return result.stdout.strip()
else:
return "Unknown Video"
def fetch(url, custom_name, ext):
title = get_video_title(url)
#
max_length = 50 #
truncated_title = title[:max_length].strip()
filename = f"{custom_name}.{ext}" if custom_name else f"{truncated_title}.{ext}"
opts = {
"mp3": ["-f", "ba", "-x", "--audio-format", "mp3"],
"wav": ["-f", "ba", "-x", "--audio-format", "wav"],
}[ext]
command = ["yt-dlp"] + opts + [url, "-o", filename]
subprocess.run(command)
return filename
with gr.Blocks() as demo:
used_letters_var = gr.State([])
with gr.Column():
gr.Markdown("# YT_DLP GRADIO DEMO")
gr.Markdown("Please press like button to support me :]")
with gr.Row() as row:
with gr.Column():
url = gr.Textbox(label="URL INPUT")
custom_name = gr.Textbox(label="Custom Name (defalut if you want!)")
outputs = gr.Audio(label="outputs")
with gr.Column():
btn = gr.Button("download!")
btn.click(
fetch,
[url],
[outputs]
)
demo.launch(debug=True, share=True) |