Next
Update app.py
1b0583a verified
raw
history blame
1.36 kB
import gradio as gr
import os
def download_url(url, name, ext):
opts = {
"mp3": '-f "ba" -x --audio-format mp3',
"mp4": '-f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"',
}[ext]
filename = f"{name}.{ext}"
os.system(f"yt-dlp {opts} {url} -o {filename}")
return filename
with gr.Blocks(theme="Nex432/green") as demo:
with gr.Tab("main settings"):
url = gr.Textbox(label="Media URL")
name_file = gr.Textbox(label="Media Name")
format = gr.Dropdown(label="Format File", choices=["mp3", "mp4"])
download = gr.Button("Download")
audio_output = gr.Audio(visible=False)
video_output = gr.Video(visible=False)
def download_media(url, name_file, format):
filename = download_url(url, name_file, format)
if format == "mp3":
return filename, None # Return filename for audio, None for video
else:
return None, filename # Return None for audio, filename for video
download.click(download_media, inputs=[url, name_file, format], outputs=[audio_output, video_output])
with gr.Tab("credits"):
gr.Markdown(
"""
Code by [Nex432](https://huggingface.co/Nex432)<br> with [ChatGPT's](https://chatgpt.com) help
"""
)
demo.launch()