-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
374 lines (285 loc) · 14.3 KB
/
main.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
import os
import subprocess
from tkinter import *
from tkinter import ttk
from tkinter import filedialog as fd
from tkinter import messagebox
import requests
import pytube
from pytube import Playlist
width = 700
height = 350
user = str(os.system("whoami"))
root = Tk()
# +400+300
root.geometry('%dx%d' % (width, height))
root.title("Download Manager")
root.config(background='#1d3557')
# turn off tabs
style = ttk.Style()
style.layout('TNotebook.Tab', [])
# create a notebook
notebook = ttk.Notebook(root)
notebook.pack(expand=True)
# create frames
home_frame = Frame(notebook, width=width, height=height, bg='#1d3557')
any_file_frame = Frame(notebook, width=width, height=height, bg='#1d3557')
youtube_frame = Frame(notebook, width=width, height=height, bg='#1d3557')
playlist_frame = Frame(notebook, width=width, height=height, bg='#1d3557')
manger_frame = Frame(notebook, width=width, height=height, bg='#1d3557')
test = Frame(notebook, width=width, height=height, bg='#1d3557')
home_frame.pack(fill='both', expand=True)
any_file_frame.pack(fill='both', expand=True)
youtube_frame.pack(fill='both', expand=True)
playlist_frame.pack(fill='both', expand=True)
manger_frame.pack(fill='both', expand=True)
test.pack(fill='both', expand=True)
# add frames to notebook
notebook.add(home_frame)
notebook.add(any_file_frame)
notebook.add(youtube_frame)
notebook.add(playlist_frame)
notebook.add(manger_frame)
notebook.add(test)
# <------Home Frame------>
# select tap number
def select(num):
notebook.select(num)
choose_label = Label(home_frame, text="Choose Option..!", foreground='#f1faee',
background='#1d3557', font=("Helvetica", 30))
choose_label.grid(row=0, column=0, columnspan=4, pady=30)
Any_file_button = Button(home_frame, text="Any File", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=lambda: select(1))
Any_file_button.grid(row=1, column=0, padx=30, pady=20)
youtube_button = Button(home_frame, text="Youtube", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=lambda: select(2))
youtube_button.grid(row=1, column=1, padx=30, pady=20)
playlist_button = Button(home_frame, text="Playlist", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=lambda: select(3))
playlist_button.grid(row=1, column=2, padx=30, pady=20)
manage_button = Button(home_frame, text="Manage", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=lambda: select(4))
manage_button.grid(row=1, column=3, padx=30, pady=20)
# <------Any File Screen------>
# select download directory
def select_dir():
dir_entry.delete(0, 'end')
name = fd.askdirectory(parent=root, initialdir="/home/{0}/Desktop".format(user), title='Please select a directory')
dir_entry.insert(0, str(name))
def download():
# https://www.wepal.net/ar/uploads/2732018-073911PM-1.jpg
url = str(link_entry.get())
dir = str(dir_entry.get())
try:
if url.find('/'):
name = url.rsplit('/', 1)[1]
r = requests.get(url)
with open('{0}/{1}'.format(dir, name), 'wb') as f:
f.write(r.content)
messagebox.showinfo("showinfo", "Downloaded Successfully")
except Exception:
messagebox.showerror("Error", "Could not download file")
link_label = Label(any_file_frame, text='Download Link', foreground='#f1faee',
background='#1d3557', font=("Helvetica", 14))
link_label.grid(column=0, row=0, padx=10, pady=20)
link_entry = Entry(any_file_frame, width=30, font=("Helvetica", 14))
link_entry.grid(column=1, row=0)
dir_label = Label(any_file_frame, text='Directory', foreground='#f1faee',
background='#1d3557', font=("Helvetica", 14))
dir_label.grid(column=0, row=1, padx=10, pady=0)
dir_entry = Entry(any_file_frame, width=30, font=("Helvetica", 14))
dir_entry.grid(column=1, row=1)
browse_button = Button(any_file_frame, text="Browse", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=select_dir)
browse_button.grid(column=2, row=1, padx=20)
start_button = Button(any_file_frame, text="Start", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=download)
start_button.grid(column=0, row=2, columnspan=2)
home_button = Button(any_file_frame, text="Home", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=lambda: select(0))
home_button.grid(column=1, row=2, columnspan=2, pady=20)
# <------Youtube Video Screen------>
quality = IntVar()
def select_dir():
vid_dir_entry.delete(0, 'end')
name = fd.askdirectory(parent=root, title='Please select a directory')
vid_dir_entry.insert(0, str(name))
def download_vid():
# 'https://www.youtube.com/watch?v=y6Mi9ARyCzA'
global video
url = str(vid_link_entry.get())
dir = str(vid_dir_entry.get())
try:
youtube = pytube.YouTube(url)
if quality.get() == 0:
video = youtube.streams.first()
if quality.get() == 1:
video = youtube.streams.get_highest_resolution()
video.download(dir)
messagebox.showinfo("showinfo", "Downloaded Successfully")
except Exception:
messagebox.showerror("Error", "Could not download file")
def quality_selected():
if quality.get() == 0:
low_qu_button.config(fg='#e63946')
high_qu_button.config(fg='#f1faee')
if quality.get() == 1:
high_qu_button.config(fg='#e63946')
low_qu_button.config(fg='#f1faee')
vid_link_label = Label(youtube_frame, text='Video Link', foreground='#f1faee',
background='#1d3557', font=("Helvetica", 14))
vid_link_label.grid(column=0, row=0, padx=10, pady=20)
vid_link_entry = Entry(youtube_frame, width=30, font=("Helvetica", 14))
vid_link_entry.grid(column=1, row=0)
dir_label = Label(youtube_frame, text='Directory', foreground='#f1faee',
background='#1d3557', font=("Helvetica", 14))
dir_label.grid(column=0, row=1, padx=10, pady=0)
vid_dir_entry = Entry(youtube_frame, width=30, font=("Helvetica", 14))
vid_dir_entry.grid(column=1, row=1)
browse_button = Button(youtube_frame, text="Browse", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=select_dir)
browse_button.grid(column=2, row=1, padx=10)
vid_qu_label = Label(youtube_frame, text='Quality', foreground='#f1faee',
background='#1d3557', font=("Helvetica", 14))
vid_qu_label.grid(column=0, row=2)
low_qu_button = Radiobutton(youtube_frame, text="Lowest", variable=quality, value=0, command=quality_selected,
bg='#1d3557', fg='#f1faee', font=("Helvetica", 16), bd=0)
low_qu_button.grid(column=0, row=2, columnspan=2)
high_qu_button = Radiobutton(youtube_frame, text="Highest", variable=quality, value=1, command=quality_selected,
bg='#1d3557', fg='#f1faee', font=("Helvetica", 16), bd=0)
high_qu_button.grid(column=1, row=2, columnspan=2, pady=20)
start_button = Button(youtube_frame, text="Start", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=download_vid)
start_button.grid(column=0, row=4, columnspan=2)
home_button = Button(youtube_frame, text="Home", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=lambda: select(0))
home_button.grid(column=1, row=4, columnspan=2)
# <------Youtube Playlist Screen------>
playlist_quality = IntVar()
def select_dir():
play_dir_entry.delete(0, 'end')
name = fd.askdirectory(parent=root, initialdir="/home/{0}/Desktop".format(user), title='Please select a directory')
play_dir_entry.insert(0, str(name))
def download_playlist():
# https://youtube.com/playlist?list=PLRfY4Rc-GWzhdCvSPR7aTV0PJjjiSAGMs
link = str(play_link_entry.get())
dir = str(play_dir_entry.get())
try:
playlist = Playlist(link)
for video in playlist.videos:
if playlist_quality.get() == 0:
video.streams.first().download(dir)
if playlist_quality.get() == 1:
video.streams.get_highest_resolution().download(dir)
messagebox.showinfo("showinfo", "Downloaded Successfully")
except Exception:
messagebox.showerror("Error", "Could not download file")
def quality_selected():
if quality.get() == 0:
low_playlist_qu.config(fg='#e63946')
high_playlist_qu.config(fg='#f1faee')
if quality.get() == 1:
high_playlist_qu.config(fg='#e63946')
low_playlist_qu.config(fg='#f1faee')
play_link_label = Label(playlist_frame, text='Playlist Link', foreground='#f1faee',
background='#1d3557', font=("Helvetica", 14))
play_link_label.grid(column=0, row=0, padx=10, pady=20)
play_link_entry = Entry(playlist_frame, width=30, font=("Helvetica", 14))
play_link_entry.grid(column=1, row=0)
dir_label = Label(playlist_frame, text='Directory', foreground='#f1faee',
background='#1d3557', font=("Helvetica", 14))
dir_label.grid(column=0, row=1, padx=10, pady=0)
play_dir_entry = Entry(playlist_frame, width=30, font=("Helvetica", 14))
play_dir_entry.grid(column=1, row=1)
browse_button = Button(playlist_frame, text="Browse", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=select_dir)
browse_button.grid(column=2, row=1, padx=10)
play_qu_label = Label(playlist_frame, text='Quality', foreground='#f1faee',
background='#1d3557', font=("Helvetica", 14))
play_qu_label.grid(column=0, row=2)
low_playlist_qu = Radiobutton(playlist_frame, text="Lowest", variable=quality, value=0, command=quality_selected,
bg='#1d3557', fg='#f1faee', font=("Helvetica", 16), bd=0)
low_playlist_qu.grid(column=0, row=2, columnspan=2)
high_playlist_qu = Radiobutton(playlist_frame, text="Highest", variable=quality, value=1, command=quality_selected,
bg='#1d3557', fg='#f1faee', font=("Helvetica", 16), bd=0)
high_playlist_qu.grid(column=1, row=2, columnspan=2, pady=20)
start_button = Button(playlist_frame, text="Start", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=download_playlist)
start_button.grid(column=0, row=4, columnspan=2)
home_button = Button(playlist_frame, text="Home", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=lambda: select(0))
home_button.grid(column=1, row=4, columnspan=2)
# <------Manage Screen------>
def select_file():
global filename
directory_entry.delete(0, 'end')
name_entry.delete(0, 'end')
filetypes = (('text files', '*.txt'), ('All files', '*.*'))
filename = fd.askopenfilename(title='Open a file', initialdir='/home/george/Desktop', filetypes=filetypes)
directory_entry.insert(0, str(filename))
name_entry.insert(0, str(filename.rsplit('/', 1)[-1]))
def select_dir():
new_dir_entry.delete(0, 'end')
filename = fd.askdirectory(title='Select Directory', initialdir="/home/{0}/Desktop".format(user))
new_dir_entry.insert(0, str(filename))
def rename():
dir = str(directory_entry.get())
newdir = dir.rsplit('/', 1)[0] + '/'
newname = str(name_entry.get())
try:
subprocess.check_output("mv {0} {1}{2}".format(dir, newdir, newname), shell=True)
os.system("mv {0} {1}{2}".format(dir, newdir, newname))
messagebox.showinfo("showinfo", "Done Successfully")
except:
messagebox.showerror("Error", "Could Not Do This Operation")
def remove():
dir = str(directory_entry.get())
try:
subprocess.check_output("rm {0}".format(dir), shell=True)
os.system("rm {0}".format(dir))
messagebox.showinfo("showinfo", "Done Successfully")
except :
messagebox.showerror("Error", "Could Not Do This Operation")
def change_dir():
dir = str(directory_entry.get())
newdir = str(new_dir_entry.get() + "/" + dir.split('/')[-1])
try:
subprocess.check_output("mv {0} {1}".format(dir, newdir), shell=True)
os.system("mv {0} {1}".format(dir, newdir))
messagebox.showinfo("showinfo", "Done Successfully")
except :
messagebox.showerror("Error", "Could Not Do This Operation")
dir_label = Label(manger_frame, text='Directory', foreground='#f1faee',
background='#1d3557', font=("Helvetica", 14))
dir_label.grid(column=0, row=0, padx=10, pady=20)
directory_entry = Entry(manger_frame, width=30, font=("Helvetica", 14))
directory_entry.grid(column=1, row=0)
browse_button = Button(manger_frame, text="Browse", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=select_file)
browse_button.grid(column=2, row=0, padx=10)
dir_label = Label(manger_frame, text='New Directory', foreground='#f1faee',
background='#1d3557', font=("Helvetica", 14))
dir_label.grid(column=0, row=1, padx=10)
new_dir_entry = Entry(manger_frame, width=30, font=("Helvetica", 14))
new_dir_entry.grid(column=1, row=1)
browse_button = Button(manger_frame, text="Browse", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=select_dir)
browse_button.grid(column=2, row=1, padx=10)
name_label = Label(manger_frame, text='File Name', foreground='#f1faee',
background='#1d3557', font=("Helvetica", 14))
name_label.grid(column=0, row=2, padx=10, pady=20)
name_entry = Entry(manger_frame, width=30, font=("Helvetica", 14))
name_entry.grid(column=1, row=2)
rename_button = Button(manger_frame, text="Rename", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=rename)
rename_button.grid(column=0, row=3, padx=10, pady=30)
remove_button = Button(manger_frame, text="Remove", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=remove)
remove_button.grid(column=1, row=3)
change_dir_button = Button(manger_frame, text="Change dir", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=change_dir)
change_dir_button.grid(column=2, row=3)
home_button = Button(manger_frame, text="Home", fg='#f1faee', bg='#e63946', width=9, bd=0,
font=("Helvetica", 14), command=lambda: select(0))
home_button.grid(column=0, row=4, columnspan=4)
root.mainloop()