-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathytDownloader.py
288 lines (232 loc) · 9.9 KB
/
ytDownloader.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
import os
import ssl
import tkinter
import webbrowser
from tkinter import PhotoImage
from tkinter import filedialog
from tkinter import messagebox
import customtkinter
import ffmpy
from pytube import YouTube
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("blue")
app = customtkinter.CTk()
app.geometry("700x500")
app.title("YTDownloader")
app.resizable(False, False)
app.iconphoto(True, PhotoImage(file="ytdownloader.ico"))
# ----Fonts----
ytdwntitle = ("BebasNeue", 25)
finished = ("IndieFlower", 15)
btns = ("RobotoMono", 10)
creditfnt = ("Cantarell", 10)
# ----Default file path----
filepath = os.path.join(os.path.expanduser("~"), "Desktop")
def main():
ssl._create_default_https_context = ssl._create_unverified_context
directory(True)
app.mainloop()
def confirm():
link = ytlink.get()
if not link:
messagebox.showwarning("YTDOWNLOADER", "No valid link in input field")
else:
yt = YouTube(link)
vidtitle = yt.title
numviews = yt.views
vidlen = yt.length
title = customtkinter.CTkLabel(master=frame,
text=f"Title : {vidtitle}")
title.place(relx=0.05,
rely=0.35,
anchor="w")
views = customtkinter.CTkLabel(master=frame,
text=f"Number of Views : {numviews:,}")
views.place(relx=0.05,
rely=0.5,
anchor="w")
length = customtkinter.CTkLabel(master=frame,
text=f"Length of Video : {vidlen} secs")
length.place(relx=0.05,
rely=0.65,
anchor="w")
def download_mp4():
link = ytlink.get()
if not link:
messagebox.showwarning("YTDOWNLOADER", "No valid link in input field")
else:
confirm()
yt = YouTube(link)
ys = yt.streams.get_highest_resolution()
ys.download(output_path=filepath)
messagebox.showinfo("YTDOWNLOADER", "Successfully Downloaded")
def download_mp3():
link = ytlink.get()
if not link:
messagebox.showwarning("YTDOWNLOADER", "No valid link in input field")
else:
confirm()
yt = YouTube(link)
ys = yt.streams.filter(only_audio=True, file_extension='webm').first()
ys.download(output_path=filepath, filename="Output.webm")
ff = ffmpy.FFmpeg(
inputs={f'{filepath}/Output.webm': None},
outputs={f'{filepath}/{yt.title} - Audio.mp3': None})
ff.run()
os.remove(f'{filepath}/Output.webm')
messagebox.showinfo("YTDOWNLOADER", "Successfully Downloaded"),
def download_webm():
link = ytlink.get()
if not link:
messagebox.showwarning("YTDOWNLOADER", "No valid link in input field")
else:
confirm()
yt = YouTube(link)
ys = yt.streams.filter(file_extension='webm').first()
ys.download(output_path=filepath)
messagebox.showinfo("YTDOWNLOADER", "Successfully Downloaded")
def developer():
webbrowser.open_new(r"https://github.com/itzkavindu/")
def openweb():
webbrowser.open_new(r"https://github.com/itzkavindu/ytDownloader")
# -----------------------------Frame---------------------------
frame = customtkinter.CTkFrame(master=app,
width=600,
height=150,
corner_radius=10,
border_width=7,
border_color="black",
fg_color="#181818")
frame.place(relx=0.5,
rely=0.7,
anchor=tkinter.CENTER)
# ----------------------------Title----------------------------
mainlab = customtkinter.CTkLabel(master=app,
text="YTDOWNLOADER",
text_font=ytdwntitle)
mainlab.place(relx=0.5,
rely=0.1,
anchor=tkinter.CENTER)
# ----------------------------Entry----------------------------
ytlink = customtkinter.CTkEntry(master=app,
placeholder_text="YouTube Link | Enter the link of the YouTube video you wish to "
"Download",
width=550,
justify="center")
ytlink.place(relx=0.1,
rely=0.2)
# ----------------------Destination-----------------------------
destinationtext = customtkinter.CTkLabel(master=app,
text="Destination | Select the destination by clicking the browse button",
width=550,
justify="center",
fg_color="#424242")
destinationtext.place(relx=0.1,
rely=0.3)
# ----------------------Open Directory-----------------------------
def directory(first_run=False):
global filepath
if first_run:
destinationtext.configure(text=filepath, state="disabled")
else:
filepath = filedialog.askdirectory(title="Select A Dir")
destinationtext.configure(text=filepath, state="disabled")
# ------------------------Confirm Button-------------------------
confirmbtn = customtkinter.CTkButton(master=app,
text="Confirm",
command=confirm,
fg_color="white",
text_color="black",
corner_radius=25,
hover_color="#757575",
width=230,
text_font=btns)
confirmbtn.place(relx=0.329,
rely=0.5,
anchor=tkinter.CENTER)
# -----------------------Download Button-------------------------
downloadbtn = customtkinter.CTkButton(master=app,
text="Download .MP4",
command=download_mp4,
fg_color="white",
text_color="black",
corner_radius=25,
hover_color="#757575",
width=160,
cursor="hand1",
text_font=btns)
downloadbtn.place(relx=0.494,
rely=0.42,
anchor=tkinter.CENTER)
# ---------------------Download audio Button-----------------------
audiodown = customtkinter.CTkButton(master=app,
text="Download .MP3",
command=download_mp3,
fg_color="white",
text_color="black",
corner_radius=25,
hover_color="#757575",
width=160,
cursor="hand1",
text_font=btns)
audiodown.place(relx=0.25,
rely=0.42,
anchor=tkinter.CENTER)
# ---------------------Download audio Button-----------------------
webmdown = customtkinter.CTkButton(master=app,
text="Download .WEBM",
command=download_webm,
fg_color="white",
text_color="black",
corner_radius=25,
hover_color="#757575",
width=160,
cursor="hand1",
text_font=btns)
webmdown.place(relx=0.74,
rely=0.42,
anchor=tkinter.CENTER)
# -----------------------OpenDir Button-------------------------
opendir = customtkinter.CTkButton(master=app,
text="Browse",
command=directory,
fg_color="white",
text_color="black",
corner_radius=25,
hover_color="#757575",
width=230,
cursor="hand1",
text_font=btns)
opendir.place(relx=0.68,
rely=0.5,
anchor=tkinter.CENTER)
# --------------YTDownloader on GitHub Button---------------------
githubrepo = customtkinter.CTkButton(master=app,
text="YTDownloader on GitHub",
command=openweb,
corner_radius=50,
cursor="hand1",
fg_color="white",
text_color="#171515",
hover_color="#757575",
width=900,
text_font=creditfnt)
githubrepo.place(relx=0.5,
rely=0.9,
anchor="center")
# ---------YTDownloader by Kavindu Nimsara 2022 Button-------------
dev = customtkinter.CTkButton(master=app,
text="YTDownloader by Kavindu Nimsara 2022",
width=800,
fg_color="black",
text_color="white",
command=developer,
hover_color="grey",
cursor="heart",
text_font=creditfnt)
dev.place(relx=0.5,
rely=0.95,
anchor=tkinter.CENTER)
# -----------------------------------------------------------------
if __name__ == "__main__":
main()