lakshminarayana commited on
Commit
c5550d7
·
1 Parent(s): c206fb2

added app file

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import yt_dlp
3
+ import os
4
+
5
+ def download_video(url):
6
+ try:
7
+ # Set options for yt-dlp to get the best video/audio quality and save as .mp4
8
+ ydl_opts = {
9
+ 'format': 'bestvideo+bestaudio/best', # Best video and audio stream combination
10
+ 'outtmpl': 'downloads/%(title)s.%(ext)s', # Save the video in the 'downloads' folder
11
+ 'merge_output_format': 'mp4', # Force merge output to .mp4
12
+ }
13
+
14
+ # Create the downloads directory if it doesn't exist
15
+ if not os.path.exists('downloads'):
16
+ os.makedirs('downloads')
17
+
18
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
19
+ info_dict = ydl.extract_info(url, download=True)
20
+ video_path = os.path.join('downloads', f"{info_dict['title']}.mp4")
21
+
22
+ # Return the path of the downloaded video file for the user to download
23
+ return video_path
24
+
25
+ except Exception as e:
26
+ return f"Error: {str(e)}"
27
+
28
+ # Create the Gradio interface
29
+ iface = gr.Interface(
30
+ fn=download_video,
31
+ inputs=gr.Textbox(label="Enter the YouTube URL"),
32
+ outputs=gr.File(label="Download Video"),
33
+ title="YouTube Video Downloader",
34
+ description="Enter the URL of the YouTube video you want to download."
35
+ )
36
+
37
+ # Launch the interface
38
+ iface.launch()