File size: 1,518 Bytes
af28c41 a74c154 5099e75 a74c154 9a2b388 a74c154 5099e75 e7c6748 a74c154 5099e75 a74c154 e7c6748 a74c154 e7c6748 a74c154 e7c6748 5099e75 a74c154 e7c6748 5099e75 a74c154 e7c6748 a74c154 e7c6748 5099e75 a74c154 e7c6748 5099e75 a74c154 5099e75 a74c154 |
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 46 47 48 49 50 |
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()
|