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