Completed
Push — master ( 59b480...390ccf )
by Deepak
20s queued 12s
created

Main.py (1 issue)

Severity
1
#------------------Import Files-------------------------------------------------
2
import os
3
import time
4
import pytube
5
from pytube import YouTube
6
from pytube import Playlist
7
from tkinter import *
8
from tkinter import messagebox
9
from tkinter import filedialog
10
import tkinter as tk
11
from tkinter import ttk
12
13
14
# Toplevel is used for Supporting the Background Image
15
top = tk.Tk()
16
tabControl=ttk.Notebook(top)
17
18
DisFont = font=('Comic Sans MS',14)
19
SubFont = font=('Comic Sans MS',12)
20
#self.progressBar()
21
tab1=ttk.Frame(tabControl)
22
tabControl.add(tab1, text='Youtube')
23
24
tab2=ttk.Frame(tabControl)
25
tabControl.add(tab2, text='Facebook',)
26
27
tabControl.pack(expand=1, fill="both")
28
top.iconbitmap('YoutubeDownloader.ico')         # Icon
29
top.title("FYI Download Manager :")             # Title
30
top.geometry("800x500")                         # Resolution
31
#photo = PhotoImage(file = "mainbg.png")
32
#w = Label(tab1, image=photo)
33
#w.pack()
34
top.resizable(0, 0)                             # Disable the Maximize
35
#-----------Close Function-----------------------------------------------------
36
def close_btn():
37
    if messagebox.askyesno("FYI...", "Are you Sure you want to exit") == True:
38
            top.withdraw()
39
            top.destroy()
40
            top.exit()
41
42
#------------------------------------------------------------------------------
43
var1 = StringVar()
44
large_font = ('Verdana',15)
45
url = Entry(tab1,textvariable= var1,font=large_font).place(x=60, y=100,width=500,height=30)
46
47
cancelbtn = Button(top,text="Quit",font = DisFont, cursor = 'hand2',command=close_btn,
48
                activebackground="lightgreen",activeforeground="blue").place(x = 60, y = 430,
49
                width=200, height=30 )
50
51
#----------------------Progress Loader----------------------------------------
52
#--------------Fetching Part from Youtube--------------------------------------
53
def get_fetch():
54
    resolution = Rvideo.get()
55
    Select = A_Video.get()
56
    Selection = A_Audio.get()
57
    #pb.start()
58
    try:
59
        if var1 is None:
60
            print("error")
61
        dirname = filedialog.askdirectory(parent=tab1, initialdir="/", title='Please select a directory')
62
        if (dirname):
63
            try:
64
                #   Video with Resolution
65
                if (resolution <= 3):
66
                    yt = pytube.YouTube(var1.get())
67
                    if(resolution == 1):
68
                        progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 286, mode = 'determinate')
69
                        progress_bar.place(x=60,y=140)
70
                        progress_bar.start()
71
                        messagebox.showinfo("Download","Please Wait for a Minute and Give Ok")
72
                        video = yt.streams.get_by_itag(136)
73
                        video.download(dirname)
74
75
                        #messagebox.showinfo(" Downloading.. ", "Thank You.")
76
                    elif(resolution == 2):
77
                        #messagebox.showinfo("Download","Downloading...")
78
                        video = yt.streams.first()
79
                        video.download(dirname)
80
                        #messagebox.showinfo(" Downloading.. ", "Thank You.")
81
                    elif(resolution ==3):
82
                        #messagebox.showinfo("Download","Downloading...")
83
                        video = yt.streams.get_by_itag(160)
84
                        video.download(dirname)
85
                        #messagebox.showinfo(" Downloading.. ", "Thank You.")
86
87
                #----Download Playlist----#
88
                if (Select == 1):
89
                    playlist = pytube.Playlist(var1.get())
90
                    playlist.populate_video_urls()                      # To load bulk list
91
                    messagebox.showinfo("Download","Downloading...")
92
                    playlist.download_all(dirname)
93
94
                #------Audio------#
95
                if(Selection <= 2):
96
                    link=YouTube(var1.get())
97
                    format_a=link.streams.filter(only_audio=True).all()
98
                    if(Selection==1):           #mp4
99
                        messagebox.showinfo("Download","Downloading...")
100
                        format_a[0].download(dirname)
101
                    elif(Selection==2):         #webm
102
                        messagebox.showinfo("Download","Downloading...")
103
                        format_a[1].download(dirname)
104
                progress_bar.stop()
0 ignored issues
show
The variable progress_bar does not seem to be defined for all execution paths.
Loading history...
105
                messagebox.showinfo(" Downloading.. ", "Thank You.")
106
            except:
107
                messagebox.showwarning(" FYI.. ", "Failed")
108
        else:
109
            messagebox.showwarning(" FYI. ", "Cancelled")
110
    except:
111
        messagebox.showwarning(" FYI. ", "Cancelled")
112
        sys.exit()
113
114
downbtn = Button(tab1, text = "Download", font = DisFont,
115
                  command = get_fetch,cursor = 'hand2',
116
                  activebackground = "lightgreen",
117
                  activeforeground = "blue").place(x = 500, y = 405,
118
                                                   width = 200, height = 30 )
119
name = Label(tab1, text="Enter the Link to Download",
120
             font=('Comic Sans MS',14),bg="black",fg="White").place(x=60,y=60)
121
122
#-----------------Radio button for video resolution----------------------------
123
Rvideo = IntVar()
124
resolution_label = Label(tab1, text="Video Resolution:",
125
             font=DisFont,fg="black").place(x=75,y=160)
126
R1 = Radiobutton(tab1,text = "Mp4 720",cursor = 'hand2',font=SubFont,variable =Rvideo,value=1,
127
                        command=get_fetch).place(x = 80,y = 200)
128
R2 = Radiobutton(tab1,text = "Mp4 360px",cursor = 'hand2',font=SubFont,variable=Rvideo,value=2,
129
                        command=get_fetch).place(x = 80,y = 240)
130
R3 = Radiobutton(tab1,text = "3gp 144px",cursor = 'hand2',font=SubFont,variable =Rvideo,value=3,
131
                        command=get_fetch).place(x = 80,y = 280)
132
133
#-----------------Radio button for video to Audio------------------------------
134
A_Audio = IntVar()
135
format_label = Label(tab1, text="Only Audio:",
136
             font=DisFont, fg="black").place(x=260,y=160)
137
R4 = Radiobutton(tab1,text = "Mp4 Audio",cursor = 'hand2',font=SubFont,variable =A_Audio,value=1,
138
                        command=get_fetch).place(x = 265,y = 200)
139
R5 = Radiobutton(tab1,text = "webm",cursor = 'hand2',font=SubFont,variable =A_Audio,value=2,
140
                        command=get_fetch).place(x = 265,y = 240)
141
#-----------------Radio button for Playlist video -----------------------------
142
A_Video = IntVar()
143
list_label = Label(tab1, text="Download Playlist:",
144
             font=DisFont,fg="black").place(x=430,y=160)
145
R7 = Radiobutton(tab1, text = "High (Default)", cursor='hand2', font=SubFont, variable=A_Video, value=1,
146
                        command=get_fetch).place(x = 430,y = 200)
147
148
#-----------------------------Close Function-----------------------------------
149
def on_close():
150
    python = sys.executable
151
    os.execl(python, python, * sys.argv)
152
    top.destroy()
153
154
top.protocol("WM_DELETE_WINDOW", on_close)
155
top.mainloop()
156
#------------------------------------------------------------------------------
157