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 app = gr.Interface( theme='Hev832/EasyAndCool', fn=play_audio, inputs=[ gr.Textbox(label="YouTube video address", placeholder="Paste video link here..."), gr.Textbox(label="File name", placeholder="Defaults to video title"), gr.Dropdown(value="wav", label="Format") ], outputs=[ gr.Audio(label="otputs"), description="
YouTube Audio Player
" )