YouTubejk / app.py
Akwbw's picture
Create app.py
fafc224 verified
import gradio as gr
import yt_dlp
import os
def download_video(url):
try:
# Options for downloading
ydl_opts = {
'format': 'best',
'outtmpl': 'downloads/%(title)s.%(ext)s',
'noplaylist': True,
}
if not os.path.exists('downloads'):
os.makedirs('downloads')
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=True)
file_path = ydl.prepare_filename(info)
return file_path
except Exception as e:
return str(e)
# Gm gpt UI
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("# Gm gpt - YT Video Downloader")
gr.Markdown("Link paste karo aur video download karo.")
with gr.Row():
url_input = gr.Textbox(label="YouTube URL", placeholder="https://www.youtube.com/watch?v=...")
download_btn = gr.Button("Download Now", variant="primary")
video_output = gr.File(label="Download File")
download_btn.click(fn=download_video, inputs=url_input, outputs=video_output)
demo.launch()