Passed
Push — master ( 0e330d...56ea18 )
by Deepak
01:14 queued 26s
created

Main.py (21 issues)

1
# ------------------Import Files---------------------------------------------
2
import pytube
3
from pytube import YouTube
4
from pytube import Playlist
5
import sys
6
import re
7
import requests as r
8
import wget
9
from tkinter import PhotoImage, Label, StringVar, Entry, Button, IntVar, \
10
     Radiobutton, messagebox, filedialog, Frame, X, Y, LEFT, RIGHT, \
11
         N, FLAT, CENTER, Canvas, Scrollbar, VERTICAL, BOTH, SUNKEN, SOLID
12
import tkinter as tk
13
from tkinter import ttk
14
import clipboard
15
import webbrowser
16
from tkinterhtml import HtmlFrame
17
from tkinter import Tk,Menu
18
19
# ============================ Window Design ================================
20
top = Tk()
21
# - Top is Main Screen  Intialization
22
23
# Styles and Designs Functions for Screens
24
# Color set for youtube for selectcolor, bg & activebackground #0B1D6F
25
yt_col = "#0B1D6F"  # Youtube bg Color
26
# Color set for facebook for selectcolor, bg & activebackground #075C90
27
fb_col = '#075C90' # Facebook bg Color
28
col_show = 'white'  # pure white fg
29
col_select = 'gray'  # gray for activeforeground
30
COLOR_1 = "#90B3DD" # TabControl Config Color
31
32
# Font Style and Size
33
large_font = font = ('Cascadia Mono', 16)  # style='my.head'
34
DisFont = font = ('', 14)  # style='my.default'
35
SubFont = font = ('Consolas', 12)  # style='my.sub'
36
tab_font = font = ('Consolas', 12)  # Tab font style
37
38
# ------------------------- Tab Control Style Config ----------------------
39
40
tab_show = "#90B3DD"
41
tab_select = "#C8D9EE"
42
43
# ------------------------ Screen and Tab -----------------------------------
44
45
tabControl = ttk.Notebook(top)
46
47
tab1 = ttk.Frame(tabControl)        # Tab1 - Youtube
48
tabControl.add(tab1, text='Youtube')
49
50
tab2 = ttk.Frame(tabControl)        # Tab2 - Facebook
51
tabControl.add(tab2, text='Facebook')
52
53
tab3 = ttk.Frame(tabControl)        # Tab3 - About
54
tabControl.add(tab3, text='About')
55
tabControl.pack(expand=1, fill="both")
56
57
top.iconbitmap('Assets/YoutubeDownloader.ico')  # Window Title Icon
58
top.title("FYIT Download Manager :")  # Title Label
59
top.geometry("800x500+100+100")  # Screen Size
60
61
photo = PhotoImage(file="Assets/youtube_bg.png")  # Tab1 Background
62
w = Label(tab1, image=photo)
63
w.pack()
64
65
photo2 = PhotoImage(file="Assets/facebook_bg.png")  # Tab2 Background
66
w2 = Label(tab2, image=photo2)
67
w2.pack()
68
69
top.resizable(0, 0)     # Disable the Maximize & Minimize option
70
71
# -----------Close Function--------------------------------------------------
72
73
def close_btn():
74
    if messagebox.askyesno("FYIT..", "Are you Sure you want to exit") is True:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable messagebox does not seem to be defined.
Loading history...
75
        top.withdraw()
76
        top.destroy()
77
        top.exit()
78
79
# ---------------------------------------------------------------------------
80
81
var1 = StringVar()
82
# Entry Widget for Youtube Downloader Tab
83
url = Entry(tab1, textvariable=var1, font=large_font, fg='darkblue')
84
url.place(x=70, y=117, width=500, height=30)
85
86
# Entry Widget for Facebook Downloader Tab
87
url_fb = Entry(tab2, textvariable=var1, font=large_font, fg='darkblue')
88
url_fb.place(x=70, y=117, width=500, height=30)
89
90
# Quit_button placed in tab1
91
quit_button = Button(tab1,
92
                         text="Quit",
93
                         relief=SOLID,
94
                         font=SubFont,
95
                         cursor='hand2',
96
                         command=close_btn)
97
quit_button.place(x=60, y=400, width=200, height=30)
98
99
# ----------------------- Auto URL Paste Functions --------------------------
100
temp = clipboard.paste()
101
url.insert('end', temp)
102
url_fb.insert('end', temp)
103
var1.set(temp)
104
105
def paste():  # Paste text from Clipboard - Function
106
    variable = clipboard.paste()
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable clipboard does not seem to be defined.
Loading history...
107
    url.insert('end', variable)
108
    url_fb.insert('end', variable)
109
    var1.set(variable)
110
111
def e1_delete():  # Clear text from Entry - Function
112
    url.delete(0, 'end')
113
    url_fb.delete(0, 'end')
114
115
def toggle(tog=[0]):  # Toggle Button for clear and paste
116
    tog[0] = not tog[0]
117
    if tog[0]:
118
        t_btn.config(text='Paste')
119
        t_btn1.config(text='Paste')
120
        e1_delete()
121
    else:
122
        t_btn.config(text='Clear')
123
        t_btn1.config(text='Clear')
124
        paste()
125
126
# tab1 clear & paste
127
t_btn1 = ttk.Button(tab1, text="Clear", cursor='hand2', style='my.TButton', command=toggle)
128
t_btn1.place(x=571, y=118, width=45, height=29)
129
130
# tab2 clear & paste
131
t_btn = ttk.Button(tab2, text="Clear", cursor='hand2', style='my.TButton', command=toggle)
132
t_btn.place(x=571, y=118, width=45, height=29)
133
134
# ------------------ Fetching Part from Youtube ----------------------------
135
136
new = 1
137
url1 = "https://bit.ly/site-fyit"
138
res_url = "https://github.com/DeepakChakravarthy/YoutubeDownloader-FYI/releases/download/V3.0/FYI.DOWNLOAD.EXE"
139
140
def openweb():      # Software Update response
141
	webbrowser.open(url1, new=new)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable webbrowser does not seem to be defined.
Loading history...
142
143
def update_check():     # AutoCheck Software Update and Sub Screen
144
145
    response = r.get(res_url)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable r does not seem to be defined.
Loading history...
146
147
    response.raise_for_status()
148
    if messagebox.askyesno("Software Update",
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable messagebox does not seem to be defined.
Loading history...
149
            "New Update is Availabe, Click yes to install.") is True:
150
        openweb()
151
# -------------------Youtube Function Call-----------------------------------
152
def get_fetch():
153
    resolution = Rvideo.get()
154
    Select = A_Video.get()
155
    Selection = A_Audio.get()
156
    try:
157
        update_check()
158
    except r.exceptions.HTTPError as err:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable r does not seem to be defined.
Loading history...
159
        # - No Updates
160
	    messagebox.showinfo("FYIT", "Select Location to Save the File.")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable messagebox does not seem to be defined.
Loading history...
161
162
    except r.ConnectionError as e:
163
        messagebox.showinfo("Connection Error", "Check the Internet Connection")
164
165
    try:
166
        if var1 is None:
167
            print("error")
168
        dirname = filedialog.askdirectory(parent=tab1,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable filedialog does not seem to be defined.
Loading history...
169
                                          initialdir="/",
170
                                          title='Please select a directory:')
171
        if dirname:
172
            try:
173
                # Youtube Video with Resolution
174
                if resolution <= 3:
175
                    yt = pytube.YouTube(var1.get())
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable pytube does not seem to be defined.
Loading history...
176
                    if resolution == 1:
177
                        progress_bar = ttk.Progressbar(tab1,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable ttk does not seem to be defined.
Loading history...
178
                                                       orient='horizontal',
179
                                                       length=500,
180
                                                       mode='determinate')
181
                        progress_bar.place(x=70, y=160)
182
                        progress_bar.start()
183
                        messagebox.showinfo(
184
                            "Download",
185
                            "Downloading.. Please Wait for a Minute.")
186
                        video = yt.streams.get_by_itag(22)
187
                        video.download(dirname)
188
                        messagebox.showinfo("Downloaded. ", "Thank You..")
189
                    elif resolution == 2:
190
                        progress_bar = ttk.Progressbar(tab1,
191
                                                       orient='horizontal',
192
                                                       length=500,
193
                                                       mode='determinate')
194
                        progress_bar.place(x=70, y=160)
195
                        progress_bar.start()
196
                        messagebox.showinfo("Download", "Downloading...")
197
                        video = yt.streams.first()
198
                        video.download(dirname)
199
                        messagebox.showinfo("Downloaded. ", "Thank You..")
200
                    elif resolution == 3:
201
                        progress_bar = ttk.Progressbar(tab1,
202
                                                       orient='horizontal',
203
                                                       length=500,
204
                                                       mode='determinate')
205
                        progress_bar.place(x=70, y=160)
206
                        progress_bar.start()
207
                        messagebox.showinfo("Download", "Downloading...")
208
                        video = yt.streams.get_by_itag(36)
209
                        video.download(dirname)
210
                        messagebox.showinfo("Downloaded. ", "Thank You..")
211
212
                # Download Playlist
213
                if Select == 1:
214
                    playlist = pytube.Playlist(var1.get())
215
                    progress_bar = ttk.Progressbar(tab1,
216
                                                   orient='horizontal',
217
                                                   length=500,
218
                                                   mode='determinate')
219
                    progress_bar.place(x=70, y=160)
220
                    progress_bar.start()
221
                    playlist.populate_video_urls()  # To load bulk list
222
                    messagebox.showinfo("Download", "Downloading...")
223
                    playlist.download_all(dirname)
224
                    messagebox.showinfo("Downloaded. ", "Thank You..")
225
226
                # Audio files
227
                if Selection <= 2:
228
                    link = YouTube(var1.get())
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable YouTube does not seem to be defined.
Loading history...
229
                    format_a = link.streams.filter(only_audio=True).all()
230
                    if Selection == 1:  # mp4
231
                        progress_bar = ttk.Progressbar(tab1,
232
                                                       orient='horizontal',
233
                                                       length=500,
234
                                                       mode='determinate')
235
                        progress_bar.place(x=70, y=160)
236
                        progress_bar.start()
237
                        messagebox.showinfo("Download", "Downloading...")
238
                        format_a[0].download(dirname)
239
                        messagebox.showinfo("Downloaded. ", "Thank You..")
240
                    elif Selection == 2:  # webm
241
                        progress_bar = ttk.Progressbar(tab1,
242
                                                       orient='horizontal',
243
                                                       length=500,
244
                                                       mode='determinate')
245
                        progress_bar.place(x=70, y=160)
246
                        progress_bar.start()
247
                        messagebox.showinfo("Download", "Downloading...")
248
                        format_a[1].download(dirname)
249
                        messagebox.showinfo("Downloaded. ", "Thank You..")
250
                messagebox.showinfo("FYIT", "Please Select Valid option")
251
            except Exception as a:
252
                messagebox.showwarning(" FYIT.. ", "Failed")
253
        else:
254
            messagebox.showwarning(" FYIT. ", "Cancelled")
255
    except Exception as a:
256
        messagebox.showwarning(" FYIT. ", "Cancelled")
257
        sys.exit()
258
259
downbtn = Button(tab1,
260
                 text="Download",
261
                 relief=SOLID,
262
                 font=SubFont,
263
                 command=get_fetch,
264
                 cursor='hand2' )
265
downbtn.place(x=500, y=400, width=200, height=30)   # Download button Tab1
266
yt_label = Label(tab1,
267
                 text="Enter the Link to Download",
268
                 font=large_font,
269
                 bg="#0B1D6F",
270
                 fg="White")
271
yt_label.place(x=65, y=65)                          # Label placed in Tab1
272
273
# -----------------Radio button for video resolution-------------------------
274
275
Rvideo = IntVar()       # Variable Daclaraton for Youtube Video (options)
276
resolution_label = Label(tab1,
277
                         text="Video Resolution:",
278
                         font=DisFont,
279
                         bg="#0B1D6F",
280
                         fg="white")
281
resolution_label.place(x=75, y=200)
282
R1 = Radiobutton(tab1,
283
                 text="Mp4 720",
284
                 cursor='hand2',
285
                 font=SubFont,
286
                 variable=Rvideo,
287
                 value=1,
288
                 fg=col_show,
289
                 bg=yt_col,
290
                 activebackground=yt_col,
291
                 activeforeground=col_select,
292
                 selectcolor=yt_col)
293
R1.place(x=80, y=240)
294
R2 = Radiobutton(tab1,
295
                 text="Mp4 360px",
296
                 cursor='hand2',
297
                 font=SubFont,
298
                 variable=Rvideo,
299
                 value=2,
300
                 fg=col_show,
301
                 bg=yt_col,
302
                 activebackground=yt_col,
303
                 activeforeground=col_select,
304
                 selectcolor=yt_col)
305
R2.place(x=80, y=280)
306
R3 = Radiobutton(tab1,
307
                 text="3gp 144px",
308
                 cursor='hand2',
309
                 font=SubFont,
310
                 variable=Rvideo,
311
                 value=3,
312
                 fg=col_show,
313
                 bg=yt_col,
314
                 activebackground=yt_col,
315
                 activeforeground=col_select,
316
                 selectcolor=yt_col)
317
R3.place(x=80, y=320)
318
319
# -----------------Radio button for video to Audio----------------------------
320
321
A_Audio = IntVar()      # Variable Daclaraton for Youtube Audio (options)
322
format_label = Label(tab1,
323
                     text="Only Audio:",
324
                     font=DisFont,
325
                     bg="#0B1D6F",
326
                     fg="white")
327
format_label.place(x=260, y=200)
328
R4 = Radiobutton(tab1,
329
                 text="Mp4 Audio",
330
                 cursor='hand2',
331
                 font=SubFont,
332
                 variable=A_Audio,
333
                 value=1,
334
                 fg=col_show,
335
                 bg=yt_col,
336
                 activebackground=yt_col,
337
                 activeforeground=col_select,
338
                 selectcolor=yt_col)
339
R4.place(x=265, y=240)
340
R5 = Radiobutton(tab1,
341
                 text="webm",
342
                 cursor='hand2',
343
                 font=SubFont,
344
                 variable=A_Audio,
345
                 value=2,
346
                 fg=col_show,
347
                 bg=yt_col,
348
                 activebackground=yt_col,
349
                 activeforeground=col_select,
350
                 selectcolor=yt_col)
351
R5.place(x=265, y=280)
352
353
# -----------------Radio button for Playlist video --------------------------
354
355
A_Video = IntVar()      # Variable Daclaraton for Youtube Playlist (options)
356
list_label = Label(tab1,
357
                   text="Download Playlist:",
358
                   font=DisFont,
359
                   bg="#0B1D6F",
360
                   fg="white")
361
list_label.place(x=415, y=200)
362
R7 = Radiobutton(tab1,
363
                 text="High (Default)",
364
                 cursor='hand2',
365
                 font=SubFont,
366
                 variable=A_Video,
367
                 value=1,
368
                 fg=col_show,
369
                 bg=yt_col,
370
                 activebackground=yt_col,
371
                 activeforeground=col_select,
372
                 selectcolor=yt_col)
373
R7.place(x=420, y=240)
374
375
# ======================= Facebook Control ==================================
376
377
quit_button = Button(tab2,
378
                         text="Quit",
379
                         relief=SOLID,
380
                         font=SubFont,
381
                         cursor='hand2',
382
                         command=close_btn)
383
quit_button.place(x=60, y=400, width=200, height=30)    # Quit_button placed in tab2
384
385
fb_label = Label(tab2,
386
                 text="Enter the Link to Download",
387
                 font=large_font,
388
                 bg="#075C90",
389
                 fg="White")
390
fb_label.place(x=65, y=65)      # Label placed in Tab2
391
392
def FacebookDownload():         # FacebookDownloader Main Fuction
393
    try:
394
        update_check()
395
    except r.exceptions.HTTPError as err:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable r does not seem to be defined.
Loading history...
396
	    messagebox.showinfo("FYIT", "Select Location to Download.")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable messagebox does not seem to be defined.
Loading history...
397
    except r.ConnectionError as e:
398
        messagebox.showinfo("Connection Error",
399
                            "Check the Internet Connection")
400
401
    try:
402
        html = r.get(var1.get())
403
        dirname = filedialog.askdirectory(parent=tab2,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable filedialog does not seem to be defined.
Loading history...
404
                                          initialdir="/",
405
                                          title='Please select a directory:')
406
        if dirname:
407
            hdvideo_url = re.search('hd_src:"(.+?)"', html.text)[1]
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable re does not seem to be defined.
Loading history...
408
        try:
409
            hd_url = hdvideo_url.replace('hd_src:"', '')
0 ignored issues
show
The variable hdvideo_url does not seem to be defined in case dirname on line 406 is False. Are you sure this can never be the case?
Loading history...
410
            messagebox.showinfo("FYIT", "[+] Video Started Downloading")
411
            progress_bar = ttk.Progressbar(tab2,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable ttk does not seem to be defined.
Loading history...
412
                                           orient='horizontal',
413
                                           length=500,
414
                                           mode='determinate')
415
            progress_bar.place(x=60, y=180)
416
            progress_bar.start()
417
            wget.download(hd_url, dirname)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable wget does not seem to be defined.
Loading history...
418
            ERASE_LINE = '\x1b[2K'
419
            sys.stdout.write(ERASE_LINE)
420
            messagebox.showinfo("FYIT", "Video downloaded")
421
            progress_bar.stop()
422
        except r.ConnectionError as e:
423
            messagebox.showerror("FYIT", "ConnectionError")
424
        except r.Timeout as e:
425
            messagebox.showinfo("FYIT", "Tomeout")
426
        except r.RequestException as e:
427
            messagebox.showerror("FYIT", "General Error or Invalid URL")
428
        except (KeyboardInterrupt, SystemExit):
429
            messagebox.showinfo("FYIT", "SystemExit")
430
            sys.exit()
431
        except TypeError:
432
            messagebox.showerror("FYIT", "Video May Private or InvalidURL")
433
    except Exception as e:
434
        messagebox.showwarning("FYIT", "Cancelled")
435
436
downbtnfb = Button(tab2,
437
                   text="Download",
438
                   relief=SOLID,
439
                   font=SubFont,
440
                   command=FacebookDownload,
441
                   cursor='hand2')
442
downbtnfb.place(x=500, y=400, width=200, height=30)    # Download placed in Tab2
443
444
# ======================= About Tab Control ===================================
445
446
def check_it(hyper_link):       # About tab Redirect Link (Frame1)
447
    webbrowser.open_new(hyper_link)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable webbrowser does not seem to be defined.
Loading history...
448
449
450
def find_update():              # Check Software Update - 2
451
    try:
452
        update_check()
453
        messagebox.showinfo("FYIT", "Thank You.")
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable messagebox does not seem to be defined.
Loading history...
454
    except r.ConnectionError as e:
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable r does not seem to be defined.
Loading history...
455
        messagebox.showinfo("Connection Error",
456
                            "Check the Internet Connection")
457
    except r.exceptions.HTTPError as err:
458
        messagebox.showinfo("FYIT","No Update yet..")
459
460
tab3_style = ttk.Style()
461
462
frame1 = tk.Frame(master=tab3, width=260)           # Tab3_Frame1
463
frame1.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
464
465
imge = PhotoImage(file='Assets/side_bar.png')
466
pht = Label(frame1, image=imge)
467
pht.pack()
468
469
link_1 = Label(frame1,
470
                text="How to use..?",
471
                font=tab_font,
472
                fg="blue",
473
                bg="#90B3DD",
474
                activeforeground="red",
475
                activebackground="green",
476
                cursor="hand2",
477
                underline=0)
478
link_1.place(x=20, y=260)
479
link_1.bind("<Button-1>",
480
            lambda e: check_it())
481
482
link_2 = Label(frame1,
483
                text="Help..!",
484
                font=tab_font,
485
                fg="blue",
486
                bg="#90B3DD",
487
                activeforeground="red",
488
                activebackground="green",
489
                cursor="hand2",
490
                underline=0)
491
link_2.place(x=20, y=300)
492
link_2.bind("<Button-1>",
493
            lambda e: check_it("http://bit.ly/site-fyit"))
494
495
link_3 = Label(frame1,
496
               text="Contact us..",
497
               font=tab_font,
498
               fg="blue",
499
               bg="#90B3DD",
500
               activeforeground="red",
501
               activebackground="green",
502
               cursor="hand2",
503
               underline=0)
504
link_3.place(x=20, y=340)
505
link_3.bind("<Button-1>",
506
            lambda e: check_it("https://gitter.im/FYIT-DOWNLOADER/DEV-FYI?utm_source=share-link&utm_medium=link&utm_campaign=share-link"))
507
508
link_4 = Label(frame1,
509
                text="Visit us..",
510
                font=tab_font,
511
                fg="blue",
512
                bg="#90B3DD",
513
                activeforeground="red",
514
                activebackground="green",
515
                cursor="hand2",
516
                underline=0)
517
link_4.place(x=20, y=380)
518
link_4.bind("<Button-1>",
519
            lambda e: check_it("http://bit.ly/site-fyit"))
520
521
link_5 = Button(frame1,
522
                text="Check Update..",
523
                font=tab_font,
524
                command=find_update,
525
                fg="blue",
526
                bg="#90B3DD",
527
                activeforeground="red",
528
                activebackground="#90B3DD",
529
                cursor="hand2",
530
                relief=FLAT,
531
                underline=0)
532
link_5.place(x=20, y=420)
533
link_5.config(highlightthickness=0)
534
535
frame2 = HtmlFrame(master=tab3, width=640, horizontal_scrollbar="auto")     # Tab3_Frame2
536
frame2.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
537
538
frame2.set_content(open("Assets/help.html", "r").read())
539
540
while True:
541
    import AddOn
542
top.mainloop()
543
544
545
# ----------------------------- Close Function -------------------------------
546
547
def on_close():
548
    top.destroy()
549
    sys.exit()
550
551
top.protocol("WM_DELETE_WINDOW", on_close)
552