Spaces:
Sleeping
Sleeping
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() |