-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyt_downloader.py
91 lines (62 loc) · 2.14 KB
/
yt_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from pytube import YouTube
from sys import argv
from pytube.cli import on_progress
import sys
import os
import tkinter
import customtkinter
from pytube.innertube import _default_clients
_default_clients["ANDROID_MUSIC"] = _default_clients["WEB"]
# Sys settings
customtkinter.set_appearance_mode('System')
customtkinter.set_default_color_theme('blue')
def srt_download():
try:
ytlink = link.get()
yt_obj = YouTube(ytlink, on_progress_callback=on_progress)
vid = yt_obj.streams.get_highest_resolution()
ttl.configure(text=yt_obj.title, font_weight="bold")
finish.configure(text="")
vid.download(pth)
finish.configure(text='Download Finished', text_color='white')
except:
finish.configure(text='Exception occcured during download', text_color='red')
def cncl():
app.destroy()
def on_progress(stream, chunk, bytes_remaining):
sizetotal = stream.filesize
bytes_downloaded = sizetotal - bytes_remaining
percent = bytes_downloaded/bytes_remaining * 100
progress_per.configure(text=str(int(percent)) + '%')
progress_per.update()
progressbar.set(float(percent)/100)
desktop = os.path.join(os.path.join(os.path.expanduser('~')), 'Desktop')
pth = desktop + '/Youtube Download/'
if os.path.exists(pth) == False:
os.makedirs(pth)
# initialise app frame
app = customtkinter.CTk()
app.geometry('740x480')
app.title('Youtube Downloader')
# UI elems
ttl = customtkinter.CTkLabel(app, text="Youtube Link")
ttl.pack(padx=10, pady=10)
url = tkinter.StringVar()
link = customtkinter.CTkEntry(app, width=250, height=40, textvariable=url)
link.pack()
#Progress bar
progress_per = customtkinter.CTkLabel(app, text="0%")
progress_per.pack()
progressbar = customtkinter.CTkProgressBar(app, width=200)
progressbar.set(0)
progressbar.pack(padx=10, pady=10)
#Download Button
dwnld = customtkinter.CTkButton(app, text='Download', command=srt_download)
dwnld.pack(padx=10, pady=10)
#Cancel Button
cancel = customtkinter.CTkButton(app, text="Cancel", command=cncl)
cancel.pack(padx=10, pady=10)
finish = customtkinter.CTkLabel(app, text=" ")
finish.pack()
# Run the application
app.mainloop()