|
import gradio as gr |
|
import yt_dlp |
|
import os |
|
import re |
|
import time |
|
from moviepy.video.io.VideoFileClip import VideoFileClip |
|
|
|
|
|
def download_video(url): |
|
download_path = './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 |
|
|
|
|
|
def gradio_interface(): |
|
with gr.Blocks() as demo: |
|
gr.Markdown("# YouTube Video Downloader") |
|
gr.Markdown("Enter the YouTube URL to download the video.") |
|
|
|
|
|
url_input = gr.Textbox(label="YouTube URL", placeholder="Enter YouTube video URL here...") |
|
|
|
|
|
output = gr.Textbox(label="Status") |
|
video_link = gr.File(label="Download Link") |
|
|
|
|
|
download_btn = gr.Button("Download Video") |
|
|
|
|
|
download_btn.click(download_video, inputs=url_input, outputs=[output, video_link]) |
|
|
|
return demo |
|
|
|
|
|
if __name__ == "__main__": |
|
gradio_interface().launch() |
|
|