Ytstock / app.py
Artificial-superintelligence's picture
Update app.py
e7c6748 verified
raw
history blame
1.52 kB
import gradio as gr
import yt_dlp
import os
import re
import time
from moviepy.video.io.VideoFileClip import VideoFileClip
# Function to download video
def download_video(url):
download_path = './downloads' # Folder to store downloads
if not os.path.exists(download_path):
os.makedirs(download_path)
ydl_opts = {
'outtmpl': download_path + '/%(title)s.%(ext)s',
}
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(url, download=False)
title = info_dict.get('title', None)
ydl.download([url])
return f"Downloaded successfully: {title}", f"/downloads/{title}.mp4"
except Exception as e:
return f"Error: {e}", None
# Create Gradio interface
def gradio_interface():
with gr.Blocks() as demo:
gr.Markdown("# YouTube Video Downloader")
gr.Markdown("Enter the YouTube URL to download the video.")
# Input for YouTube URL
url_input = gr.Textbox(label="YouTube URL", placeholder="Enter YouTube video URL here...")
# Output display
output = gr.Textbox(label="Status")
video_link = gr.File(label="Download Link")
# Download button
download_btn = gr.Button("Download Video")
# Define the action on button click
download_btn.click(download_video, inputs=url_input, outputs=[output, video_link])
return demo
# Launch the interface
if __name__ == "__main__":
gradio_interface().launch()