-
Notifications
You must be signed in to change notification settings - Fork 203
/
youtube_downloader.py
81 lines (64 loc) · 2.29 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
71
72
73
74
75
76
77
78
79
80
81
from pytube import *
from tkinter import *
from tkinter.filedialog import *
from tkinter.messagebox import *
from threading import *
file_size = 0
def progress(stream=None, chunk=None, remaining=None):
file_downloaded = (file_size-remaining)
per = round((file_downloaded/file_size)*100, 1)
dBtn.config(text=f'{per}% downloaded')
def startDownload():
global file_size
try:
URL = urlField.get()
dBtn.config(text='Please wait...')
dBtn.config(state=DISABLED)
path_save = askdirectory()
if path_save is None:
return
ob = YouTube(URL, on_progress_callback=progress)
strm = ob.streams[0]
x = ob.description.split("|")
file_size = strm.filesize
dfile_size = file_size
dfile_size /= 1000000
dfile_size = round(dfile_size, 2)
label.config(text='Size: ' + str(dfile_size) + ' MB')
label.pack(side=TOP, pady=10)
desc.config(text=ob.title + '\n\n' + 'Label: ' + ob.author + '\n\n' + 'length: ' + str(round(ob.length/60, 1)) + ' mins\n\n'
'Views: ' + str(round(ob.views/1000000, 2)) + 'M')
desc.pack(side=TOP, pady=10)
strm.download(path_save, strm.title)
dBtn.config(state=NORMAL)
showinfo("Download Finished", 'Downloaded Successfully')
urlField.delete(0, END)
label.pack_forget()
desc.pack_forget()
dBtn.config(text='Start Download')
except Exception as e:
print(e)
print('Error!!')
def startDownloadthread():
thread = Thread(target=startDownload)
thread.start()
main = Tk()
main.title("My YouTube Downloader")
main.config(bg='#3498DB')
main.iconbitmap('images\\youtube-ios-app.ico')
main.geometry("500x600")
file = PhotoImage(
file='images\\photo.png')
headingIcon = Label(main, image=file)
headingIcon.pack(side=TOP)
urlField = Entry(main, font=("Times New Roman", 18), justify=CENTER)
urlField.pack(side=TOP, fill=X, padx=10, pady=15)
dBtn = Button(main, text="Start Download", font=(
"Times New Roman", 18), relief='ridge', activeforeground='red', command=startDownloadthread)
dBtn.pack(side=TOP)
label = Label(main, text='')
desc = Label(main, text='')
author = Label(main, text="@G.S.")
author.config(font=("Courier", 44))
author.pack(side=BOTTOM)
main.mainloop()