-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube_downloader.py
70 lines (51 loc) · 2.3 KB
/
youtube_downloader.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
69
70
import tkinter
import customtkinter
from pytube import YouTube
import pytube.exceptions
customtkinter.set_appearance_mode('dark')
def startDownload():
try:
ytLink = url_var.get()
ytObject = YouTube(ytLink, on_progress_callback=on_progress)
video = ytObject.streams.get_highest_resolution()
title.configure(text=ytObject.title, text_color = "white")
video.download(r'C:\Users\tahai\Documents\offline_vids')
finishLabel.configure(text = "Downloaded")
except pytube.exceptions.AgeRestrictedError:
finishLabel.configure(text= "Video cannot be downloaded due top age restriction ", text_color = "red")
except pytube.exceptions.RegexMatchError:
finishLabel.configure(text = "Please enter a valid link")
def on_progress(stream, chunk, bytes_remaining):
total_size = stream.filesize
bytes_downloaded = total_size - bytes_remaining
percentage_of_completion = bytes_downloaded / total_size * 100
per = str(int(percentage_of_completion))
pPercentage.configure(text = per + "%")
pPercentage.update()
def startDownloadTest():
ytLink = url_var.get()
ytObject = YouTube(ytLink)
video = ytObject.streams.get_highest_resolution()
title.configure(text=ytObject.title, text_color = "white")
video.download(r'C:\Users\tahai\Documents\offline_vids')
finishLabel.configure(text = "Downloaded")
# Our app frame
app = customtkinter.CTk()
app.geometry("720x480")
app.title("Youtube Downloader")
app.iconbitmap(r'images\youtube_logo.ico')
#Adding UI elements
title = customtkinter.CTkLabel(app, text= "Insert youtube link ", font=("Segoe UI", 12))
title.pack(padx = 10, pady=10)
url_var = tkinter.StringVar()
link = customtkinter.CTkEntry(app, width = 350, height = 40, textvariable = url_var, font=("Segoe UI", 12))
link.pack()
finishLabel = customtkinter.CTkLabel(app, text = "", font=("Segoe UI", 12))
finishLabel.pack(padx=10, pady= 10)
#Progress Percentage
pPercentage = customtkinter.CTkLabel( app, text = '0%', font=("Segoe UI", 30), text_color="red")
pPercentage.pack()
download = customtkinter.CTkButton(app, text = "Download", font=("Segoe UI", 12), command = startDownload, fg_color=("red", "red"), text_color=("white", "white"), hover_color=("red", "red"))
download.pack(padx= 10, pady = 10)
# Run app
app.mainloop()