KristofGaming39 commited on
Commit
01f7b4a
1 Parent(s): 4f1e2b9

Create main.py

Browse files

# **REMEMBER TO ASK PERMISSION TO DOWNLOAD FROM THE CREATOR OF THAT VIDEO -- FOR COPYRIGHT**

This is a **FREE** Youtube video downloader, only **supports MP4 with audio**.

Files changed (1) hide show
  1. main.py +53 -0
main.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install yt-dlp gradio
2
+ import yt_dlp
3
+ import gradio as gr
4
+ import os
5
+ import shutil
6
+
7
+ # Function to download YouTube video
8
+ def download_video(url):
9
+ try:
10
+ # Temporary file path to save the downloaded video
11
+ download_folder = 'downloads'
12
+ if not os.path.exists(download_folder):
13
+ os.makedirs(download_folder)
14
+
15
+ # Setting the options for yt-dlp
16
+ ydl_opts = {
17
+ 'format': 'best', # best available quality
18
+ 'noplaylist': True, # avoid downloading playlists
19
+ 'outtmpl': os.path.join(download_folder, '%(title)s.%(ext)s'), # save in 'downloads' folder
20
+ }
21
+
22
+ # Initialize yt-dlp
23
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
24
+ # Download the video
25
+ info_dict = ydl.extract_info(url, download=True)
26
+ video_title = info_dict.get('title', 'downloaded_video')
27
+ video_file_path = os.path.join(download_folder, f"{video_title}.mp4")
28
+
29
+ # Return the path to the downloaded video so Gradio can make it available for download
30
+ return video_file_path
31
+
32
+ except Exception as e:
33
+ # In case of error
34
+ return f"An error occurred: {e}"
35
+
36
+ # Create Gradio interface
37
+ def create_interface():
38
+ # Interface Layout
39
+ interface = gr.Interface(
40
+ fn=download_video, # Function to call on submit
41
+ inputs=gr.Textbox(label="YouTube Video URL", placeholder="Enter the video URL here", lines=1),
42
+ outputs=gr.File(label="Download Your Video"), # Provide a download link
43
+ title="YouTube Video Downloader", # Title of the Interface
44
+ description="Enter a YouTube video URL to download it as an MP4 with audio included.",
45
+ theme="compact", # Make it compact and clean
46
+ )
47
+
48
+ return interface
49
+
50
+ # Run Gradio Interface
51
+ if __name__ == "__main__":
52
+ interface = create_interface()
53
+ interface.launch()