Spaces:
Running
Running
File size: 1,309 Bytes
29ded09 53b8e30 0014839 53b8e30 0014839 d1c57b1 0014839 90be0a7 0014839 90be0a7 0014839 29ded09 0014839 |
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 |
import gradio as gr
import yt_dlp
import os
def download_media(url, output_format):
ydl_opts = {}
if output_format == "Audio":
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': 'downloads/%(title)s.%(ext)s',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
elif output_format == "Video":
ydl_opts = {
'format': 'bestvideo+bestaudio/best',
'outtmpl': 'downloads/%(title)s.%(ext)s',
}
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
return "Download successful!"
except Exception as e:
return f"Error: {str(e)}"
# Gradio Blocks UI
with gr.Blocks() as demo:
gr.Markdown("# Video and Audio Downloader using yt-dlp")
with gr.Row():
url_input = gr.Textbox(label="Video/Audio URL")
format_dropdown = gr.Dropdown(choices=["Audio", "Video"], label="Output Format")
download_button = gr.Button("Download")
output_text = gr.Textbox(label="Output Message")
download_button.click(download_media, inputs=[url_input, format_dropdown], outputs=output_text)
demo.launch()
|