-
Notifications
You must be signed in to change notification settings - Fork 12.3k
/
youtubedownloader.py
66 lines (55 loc) · 1.47 KB
/
youtubedownloader.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
from tkinter import *
from tkinter import filedialog, messagebox
from threading import Thread
from pytube import YouTube
def threading():
# Call work function
t1 = Thread(target=download)
t1.start()
def download():
try:
url = YouTube(str(url_box.get()))
video = url.streams.first()
filename = filedialog.asksaveasfilename(defaultextension=".mp4", filetypes=[("MP4 files", "*.mp4")])
if filename: # Check if a filename is selected
video.download(filename=filename)
messagebox.showinfo('', 'Download completed!')
else:
messagebox.showwarning('', 'Download cancelled!')
except Exception as e:
messagebox.showerror("Error", "An error occurred while downloading the video.")
root = Tk()
root.title('YouTube Downloader')
root.geometry('780x500+200+200')
root.configure(bg='olivedrab1')
root.resizable(False, False)
# Label widgets
introlable = Label(
root,
text='YouTube Video Downloader',
width=30,
relief='ridge',
bd=4,
font=('chiller', 26, 'italic bold'),
fg='red')
introlable.place(x=35, y=20)
Label(
root,
text='Enter YouTube Link',
font=('sans-serif', 16),
bg='olivedrab1'
).place(x=40, y=150)
url_box = Entry(
root,
font=('arial', 30),
width=30
)
url_box.place(x=40, y=180)
btn = Button(
root,
text='DOWNLOAD',
font=('sans-serif', 25),
command=threading
)
btn.place(x=270, y=240)
root.mainloop()