Passed
Push — master ( 1b73aa...6f5510 )
by Deepak
01:15 queued 11s
created

Main.pb_bar()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
# ------------------Import Files-----------------------------------------
2
import os
3
import time
4
import pytube
5
from pytube import YouTube
6
from pytube import Playlist
7
import sys
8
import re
9
import requests as r
10
import wget
11
from tkinter import *
12
from tkinter import messagebox
13
from tkinter import filedialog
14
import tkinter as tk
15
from tkinter import ttk
16
17
# Toplevel is used for Supporting the Background Image
18
top = tk.Tk()
19
tabControl = ttk.Notebook(top)
20
DisFont = font = ('Comic Sans MS', 16)
21
SubFont = font = ('Comic Sans MS', 12)
22
tab1 = ttk.Frame(tabControl)
23
tabControl.add(tab1, text='Youtube')
24
25
tab2 = ttk.Frame(tabControl)
26
tabControl.add(tab2, text='Facebook',)
27
28
tabControl.pack(expand=1, fill="both")
29
top.iconbitmap('Assets/YoutubeDownloader.ico')     # Icon
30
top.title("FYI Download Manager :")             # Title
31
top.geometry("800x500")                         # Resolution
32
33
photo = PhotoImage(file="Assets/youtube_bg.png")
34
w = Label(tab1, image=photo)
35
w.pack()
36
37
photo2 = PhotoImage(file="Assets/facebook_bg.png")
38
w2 = Label(tab2, image=photo2)
39
w2.pack()
40
top.resizable(0, 0)                             # Disable the Maximize
41
42
# -----------Close Function--------------------------------------------------
43
def close_btn():
44
    if messagebox.askyesno("FYI...", "Are you Sure you want to exit") is True:
45
        top.withdraw()
46
        top.destroy()
47
        top.exit()
48
49
# ---------------------------------------------------------------------------
50
var1 = StringVar()
51
large_font = ('Verdana', 15)
52
url = Entry(tab1, textvariable=var1,
53
                    font=large_font).place(x=60, y=100, width=500, height=30)
54
55
cancelbtn = Button(top, text="Quit", font=DisFont, cursor='hand2',
56
            command=close_btn, activebackground="lightgreen",
57
            activeforeground="blue").place(x=60, y=430, width=200, height=30)
58
59
# --------------Fetching Part from Youtube----------------------------------
60
def get_fetch():
61
    resolution = Rvideo.get()
62
    Select = A_Video.get()
63
    Selection = A_Audio.get()
64
    # pb.start()
65
    try:
66
        if var1 is None:
67
            print("error")
68
        dirname = filedialog.askdirectory(parent=tab1, initialdir="/",
69
                    title='Please select a directory')
70
        if dirname:
71
            try:
72
                # Video with Resolution
73
                if resolution <= 3:
74
                    yt = pytube.YouTube(var1.get())
75
                    if resolution == 1:
76
                        progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate')
77
                        progress_bar.place(x=60,y=140)
78
                        progress_bar.start()
79
                        messagebox.showinfo("Download",
80
                            "Downloading.. Please Wait for a Minute.")
81
                        video = yt.streams.get_by_itag(22)
82
                        video.download(dirname)
83
                    elif resolution == 2:
84
                        progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate')
85
                        progress_bar.place(x=60,y=140)
86
                        progress_bar.start()
87
                        messagebox.showinfo("Download","Downloading...")
88
                        video = yt.streams.first()
89
                        video.download(dirname)
90
                    elif resolution == 3:
91
                        progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate')
92
                        progress_bar.place(x=60,y=140)
93
                        progress_bar.start()
94
                        messagebox.showinfo("Download","Downloading...")
95
                        video = yt.streams.get_by_itag(36)
96
                        video.download(dirname)
97
                # Download Playlist
98
                if Select == 1:
99
                    playlist = pytube.Playlist(var1.get())
100
                    progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate')
101
                    progress_bar.place(x=60,y=140)
102
                    progress_bar.start()
103
                    playlist.populate_video_urls()          # To load bulk list
104
                    messagebox.showinfo("Download", "Downloading...")
105
                    playlist.download_all(dirname)
106
107
                # Audio files
108
                if Selection <= 2:
109
                    link = YouTube(var1.get())
110
                    format_a = link.streams.filter(only_audio=True).all()
111
                    if Selection == 1:
112
                        # mp4
113
                        progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate')
114
                        progress_bar.place(x=60,y=140)
115
                        progress_bar.start()
116
                        messagebox.showinfo("Download", "Downloading...")
117
                        format_a[0].download(dirname)
118
                    elif Selection == 2:                # webm
119
                        progress_bar = ttk.Progressbar(tab1, orient = 'horizontal', length = 500, mode = 'determinate')
120
                        progress_bar.place(x=60,y=140)
121
                        progress_bar.start()
122
                        messagebox.showinfo("Download", "Downloading...")
123
                        format_a[1].download(dirname)
124
                
125
                messagebox.showinfo("Downloading.. ", "Thank You.")
126
            except Exception as a:
127
                #print(a)
128
                messagebox.showwarning(" FYI.. ", "Failed")
129
        else:
130
            messagebox.showwarning(" FYI. ", "Cancelled")
131
    except Exception as a:
132
        messagebox.showwarning(" FYI. ", "Cancelled")
133
        #print(a)
134
        sys.exit()
135
136
downbtn = Button(tab1, text="Download", font=DisFont,
137
        command=get_fetch, cursor='hand2', activebackground="lightgreen",
138
        activeforeground="blue").place(x=500, y=405, width=200, height=30)
139
name = Label(tab1, text="Enter the Link to Download",
140
        font=('Comic Sans MS', 16), bg="#520B00", fg="White").place(x=60, y=60)
141
142
# -----------------Radio button for video resolution-------------------------
143
Rvideo = IntVar()
144
resolution_label = Label(tab1, text="Video Resolution:",
145
            font=DisFont, bg="#520B00", fg="white").place(x=75, y=160)
146
R1 = Radiobutton(tab1, text="Mp4 720", cursor='hand2', font=SubFont,
147
            variable=Rvideo, value=1, command=get_fetch, bg="#520B00",
148
            fg="white").place(x=80, y=200)
149
R2 = Radiobutton(tab1, text="Mp4 360px", cursor='hand2', font=SubFont,
150
            variable=Rvideo, value=2, command=get_fetch, bg="#520B00",
151
            fg="white").place(x=80, y=240)
152
R3 = Radiobutton(tab1, text="3gp 144px", cursor='hand2', font=SubFont,
153
            variable=Rvideo, value=3, command=get_fetch, bg="#520B00",
154
            fg="white").place(x=80, y=280)
155
156
# -----------------Radio button for video to Audio----------------------------
157
A_Audio = IntVar()
158
format_label = Label(tab1, text="Only Audio:",
159
                font=DisFont, bg="#520B00", fg="white").place(x=260, y=160)
160
R4 = Radiobutton(tab1, text="Mp4 Audio", cursor='hand2',
161
                font=SubFont, variable=A_Audio, value=1, command=get_fetch,
162
                bg="#520B00", fg="white").place(x=265, y=200)
163
R5 = Radiobutton(tab1, text="webm", cursor='hand2', font=SubFont,
164
                variable=A_Audio, value=2, command=get_fetch,
165
                bg="#520B00", fg="white").place(x=265, y=240)
166
167
# -----------------Radio button for Playlist video --------------------------
168
A_Video = IntVar()
169
list_label = Label(tab1, text="Download Playlist:", font=DisFont,
170
                bg="#520B00", fg="white").place(x=415, y=160)
171
R7 = Radiobutton(tab1, text="High (Default)", cursor='hand2', font=SubFont,
172
                variable=A_Video, value=1, command=get_fetch, bg="#520B00",
173
                fg="white").place(x=420, y=200)
174
175
# ======================= Facebook Control ==================================
176
177
fb_line = StringVar()
178
fb_url = Entry(tab2, textvariable=fb_line,
179
                    font=large_font).place(x=60, y=100, width=500, height=30)
180
181
fb_downbtn = Button(tab2, text="Download", font=DisFont,
182
         cursor='hand2', activebackground="lightgreen",
183
        activeforeground="blue").place(x=500, y=405, width=200, height=30)
184
fb_name = Label(tab2, text="Enter the Link to Download",
185
        font=('Comic Sans MS', 16), bg="#075C90", fg="White").place(x=60, y=60)
186
187
# -----------------Radio button for video to Quality--------------------------
188
fb_link = IntVar()
189
format_label = Label(tab2, text="Select Video Quality:",
190
                font=DisFont, bg="#075C90", fg="black").place(x=75, y=160)
191
F1 = Radiobutton(tab2, text="High", cursor='hand2', font=SubFont,
192
                variable=fb_link, value=1, bg="#075C90",
193
                fg="black").place(x=80, y=200)
194
F2 = Radiobutton(tab2, text="Low", cursor='hand2', font=SubFont,
195
                variable=fb_link, value=2, bg="#075C90",
196
                fg="black").place(x=200, y=200)
197
top.mainloop()
198
# -----------------------------Close Function--------------------------------
199
def on_close():
200
    python = sys.executable
201
    os.execl(python, python, * sys.argv)
202
    top.destroy()
203
top.protocol("WM_DELETE_WINDOW", on_close)
204
# ---------------------------------------------------------------------------
205