|
import gradio as gr |
|
from yt_dlp import YoutubeDL |
|
|
|
|
|
ydl_opts = { |
|
'format': 'bestvideo+bestaudio/best', |
|
'outtmpl': '%(id)s.%(ext)s', |
|
'postprocessors': [{ |
|
'key': 'FFmpegMerger', |
|
'preferredcodec': 'mp4', |
|
}], |
|
'noplaylist': True, |
|
} |
|
|
|
def download_video(url): |
|
with YoutubeDL(ydl_opts) as ydl: |
|
info_dict = ydl.extract_info(url, download=False) |
|
ydl.download([url]) |
|
filename = ydl.prepare_filename(info_dict) |
|
return filename |
|
|
|
|
|
iface = gr.Interface( |
|
fn=download_video, |
|
inputs=gr.Textbox(placeholder="Enter YouTube URL here..."), |
|
outputs='text', |
|
title="YouTube Video Downloader", |
|
description="Enter a YouTube URL to download it as an MP4 file." |
|
) |
|
|
|
if __name__ == "__main__": |
|
iface.launch() |