-
Notifications
You must be signed in to change notification settings - Fork 12
/
yt_video_downloader.py
161 lines (128 loc) · 3.26 KB
/
yt_video_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# Please run this in your terminal 'pip install pytube3' to make this code error less
# Importing necessary packages
import tkinter as tk
from tkinter import *
from pytube import YouTube
from tkinter import messagebox, filedialog
# Defining CreateWidgets() function
# to create necessary tkinter widgets
def Widgets():
head_label = Label(root, text="YouTube Video Downloader Using Tkinter",
padx=15,
pady=15,
font="SegoeUI 14",
bg="Gray",
fg="white")
head_label.grid(row=1,
column=1,
pady=10,
padx=5,
columnspan=3)
link_label = Label(root,
text="YouTube link :",
bg="Gray",
pady=5,
padx=5)
link_label.grid(row=2,
column=0,
pady=5,
padx=5)
root.linkText = Entry(root,
width=35,
textvariable=video_Link,
font="Arial 14")
root.linkText.grid(row=2,
column=1,
pady=5,
padx=5,
columnspan=2)
destination_label = Label(root,
text="Destination :",
bg="Gray",
pady=5,
padx=9)
destination_label.grid(row=3,
column=0,
pady=5,
padx=5)
root.destinationText = Entry(root,
width=27,
textvariable=download_Path,
font="Arial 14")
root.destinationText.grid(row=3,
column=1,
pady=5,
padx=5)
browse_B = Button(root,
text="Browse",
command=Browse,
width=10,
bg="lightBlue",
relief=GROOVE)
browse_B.grid(row=3,
column=2,
pady=1,
padx=1)
Download_B = Button(root,
text="Download Video",
command=Download,
width=20,
bg="lightpink",
pady=10,
padx=15,
relief=GROOVE,
font="Georgia, 13")
Download_B.grid(row=4,
column=1,
pady=20,
padx=20)
# Defining Browse() to select a
# destination folder to save the video
def Browse():
# Presenting user with a pop-up for
# directory selection. initialdir
# argument is optional Retrieving the
# user-input destination directory and
# storing it in downloadDirectory
download_Directory = filedialog.askdirectory(
initialdir="YOUR DIRECTORY PATH", title="Save Video")
# Displaying the directory in the directory
# textbox
download_Path.set(download_Directory)
# Defining Download() to download the video
def Download():
# getting user-input Youtube Link
Youtube_link = video_Link.get()
# select the optimal location for
# saving file's
download_Folder = download_Path.get()
# Creating object of YouTube()
getVideo = YouTube(Youtube_link)
# Getting all the available streams of the
# youtube video and selecting the first
# from the
videoStream = getVideo.streams.first()
# Downloading the video to destination
# directory
videoStream.download(download_Folder)
# Displaying the message
messagebox.showinfo("SUCCESSFULLY",
"DOWNLOADED AND SAVED IN\n"
+ download_Folder)
# Creating object of tk class
root = tk.Tk()
# Setting the title, background color
# and size of the tkinter window and
# disabling the resizing property
root.geometry("520x280")
root.resizable(False, False)
root.title("YouTube Video Downloader")
root.config(background="Gray")
# Creating the tkinter Variables
video_Link = StringVar()
download_Path = StringVar()
# Calling the Widgets() function
Widgets()
# Defining infinite loop to run
# application
root.mainloop()