namelessai commited on
Commit
ded4577
·
verified ·
1 Parent(s): 5f8fc3b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import yt_dlp
3
+
4
+ def download_youtube_video(url, resolution):
5
+ ydl_opts = {
6
+ 'format': f'bestvideo[height<={resolution}]+bestaudio/best[height<={resolution}]',
7
+ 'outtmpl': '%(title)s.%(ext)s'
8
+ }
9
+
10
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
11
+ try:
12
+ info = ydl.extract_info(url, download=True)
13
+ return f"Downloaded: {info['title']}"
14
+ except Exception as e:
15
+ return f"Error: {str(e)}"
16
+
17
+ iface = gr.Interface(
18
+ fn=download_youtube_video,
19
+ inputs=[
20
+ gr.Textbox(label="YouTube URL"),
21
+ gr.Dropdown(choices=["720", "1080", "1440", "2160"], label="Resolution")
22
+ ],
23
+ outputs=gr.Textbox(label="Result"),
24
+ title="YouTube Downloader (with 4K support)",
25
+ 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."
26
+ )
27
+
28
+ iface.launch()