File size: 1,043 Bytes
ded4577
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import yt_dlp

def download_youtube_video(url, resolution):
    ydl_opts = {
        'format': f'bestvideo[height<={resolution}]+bestaudio/best[height<={resolution}]',
        'outtmpl': '%(title)s.%(ext)s'
    }
    
    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        try:
            info = ydl.extract_info(url, download=True)
            return f"Downloaded: {info['title']}"
        except Exception as e:
            return f"Error: {str(e)}"

iface = gr.Interface(
    fn=download_youtube_video,
    inputs=[
        gr.Textbox(label="YouTube URL"),
        gr.Dropdown(choices=["720", "1080", "1440", "2160"], label="Resolution")
    ],
    outputs=gr.Textbox(label="Result"),
    title="YouTube Downloader (with 4K support)",
    description="Enter a YouTube URL and select the desired resolution to download the video. Can be used as an API for AI models using Gradio's API function. Completely free to use. For faster processing and downloading duplicate the space and upgrade to CPU Upgrade."
)

iface.launch()