-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
68 lines (54 loc) · 2.28 KB
/
main.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import tkinter as tk #imports the tkinter module fro creating the graphical user interface
from tkinter import filedialog
from pytube import YouTube #imports youtube function from the pytube library
def download_video(): #creating the function to download the youtube video
video_url = url_entry.get()
output_path = output_entry.get()
selected_quality = quality_var.get()
try:
yt = YouTube(video_url, on_progress_callback=on_progress)
video = yt.streams.filter(progressive=True, file_extension='mp4', resolution=selected_quality).first()
if video:
status_label.config(text=f"Downloading: {yt.title}...")
video.download(output_path)
status_label.config(text="Download complete!")
else:
status_label.config(text="No stream available for the selected quality.")
except Exception as e:
status_label.config(text=f"Error: {str(e)}")
def browse_output_path():
folder_path = filedialog.askdirectory()
output_entry.delete(0, tk.END)
output_entry.insert(tk.END, folder_path)
def on_progress(stream, chunk, remaining):
file_size = stream.filesize
downloaded = file_size - remaining
percent = (downloaded / file_size) * 100
progress_label.config(text=f"Downloading... {percent:.1f}%")
root = tk.Tk()
root.title("YouTube Video Downloader")
url_label = tk.Label(root, text="Enter YouTube URL:")
url_label.pack()
url_entry = tk.Entry(root, width=50)
url_entry.pack()
output_label = tk.Label(root, text="Select Output Path:")
output_label.pack()
output_entry = tk.Entry(root, width=50)
output_entry.pack()
browse_button = tk.Button(root, text="Browse", command=browse_output_path)
browse_button.pack()
quality_label = tk.Label(root, text="Select Quality:")
quality_label.pack()
quality_var = tk.StringVar()
quality_var.set("720p")
qualities = ["144p", "240p", "360p", "480p", "720p", "1080p"]
for quality in qualities:
radio = tk.Radiobutton(root, text=quality, variable=quality_var, value=quality)
radio.pack()
download_button = tk.Button(root, text="Download", command=download_video)
download_button.pack()
progress_label = tk.Label(root, text="")
progress_label.pack()
status_label = tk.Label(root, text="")
status_label.pack()
root.mainloop()