1+ # ================= Importing Modules =================== 
2+ from  tkinter  import  * 
3+ import  tkinter  as  tk 
4+ from  datetime  import  datetime 
5+ from  PIL  import  ImageTk , Image 
6+ from  tkinter .filedialog  import  askdirectory 
7+ from  tkinter  import  messagebox 
8+ import  time 
9+ from  pytube  import  YouTube 
10+ from  pytube  import  Playlist 
11+ from  tkinter .ttk  import  Progressbar 
12+ from  tkinter .scrolledtext  import  ScrolledText 
13+ #https://youtu.be/GvTcpfSnOMQ 
14+ # =========================================================== 
15+ 
16+ class  YoutubeDownloader ():
17+ 
18+         # ========== Video Path =================== 
19+         def  select_v_path (self ):
20+                 self .location  =  askdirectory ()
21+ 
22+                 if  self .video_path .get () !=  "" :
23+                         self .video_path .delete (0 ,END )
24+                         self .video_path .insert (END ,self .location )
25+                 else :
26+                         self .video_path .insert (END ,self .location )
27+                 
28+         # ============= Playlist Path ================ 
29+         def  select_p_path (self ):
30+                 self .location  =  askdirectory ()
31+ 
32+                 if  self .playlist_path .get () !=  "" :
33+                         self .playlist_path .delete (0 ,END )
34+                         self .playlist_path .insert (END ,self .location )
35+                 else :
36+                         self .playlist_path .insert (END ,self .location )
37+         
38+         
39+         # =======================  Downloading Video ==================== 
40+         def  download_video (self ):
41+                 if  self .video_url .get () ==  "" :
42+                         messagebox .showerror ("Error" ,"Please Paste Video URL" )
43+                 elif  'https://'  not  in self .video_url .get ():
44+                          messagebox .showerror ("Error" ,"Wrong Video Url" )
45+                 elif  self .video_path .get () ==  "" :
46+                         messagebox .showerror ("Error" ,"Please provide Path" )
47+                 else :
48+                         try :
49+ 
50+                                 self .url  =  self .video_url .get ()
51+                                 self .path  =  self .video_path .get ()
52+                                 self .video  =  YouTube (self .url )
53+                                 self .stream  =  self .video .streams .filter (only_audio = False ).first ()
54+                                 print ("download started" ,self .video .title )
55+                                 
56+                                 print ("download completed" ,self .video .title )
57+ 
58+                                 self .root  =  tk .Tk ()
59+                                 self .root .geometry ('300x150' )
60+                                 self .root .maxsize (300 ,150 )
61+                                 self .root .minsize (300 ,150 )
62+                                 self .root .title ('Video Dowloading' )
63+                                 self .root ['bg' ] =  "white" 
64+ 
65+                                 
66+                                 self .start_downloading  =  Label (self .root ,text = "Video downloading ....." ,fg = "red" ,font = ('verdana' ,10 ,'bold' ),bg = "white" )
67+                                 self .start_downloading .place (x = 40 ,y = 10 )
68+ 
69+                                 self .stream .download (output_path  =  self .path ,filename = None )
70+                                 
71+                                 self .progress  =  Progressbar (self .root ,orient  =  HORIZONTAL ,length = 250 ,mode = 'determinate' )
72+                                 self .progress ['value' ] =  20 
73+                                 self .root .update_idletasks ()
74+                                 self .progress ['value' ] =  40 
75+                                 self .root .update_idletasks ()
76+                                 self .progress ['value' ] =  60 
77+                                 self .root .update_idletasks ()
78+                                 self .progress ['value' ] =  80 
79+                                 self .root .update_idletasks ()
80+                                 self .progress ['value' ] =  100 
81+                                 self .root .update_idletasks ()
82+                                 self .progress .place (x = 20 ,y = 40 )
83+ 
84+                                 self .dow_details  =  ScrolledText (self .root ,width = 30 ,height = 3 ,font = ('verdana' ,8 ,'bold' ))
85+                                 self .dow_details .place (x = 20 ,y = 70 )
86+                                 self .dow_details .insert (END ,f'{ self .video_path .get ()} \n  { self .video .title }  )
87+ 
88+                                 self .dow_success  =  Label (self .root ,text = "Video downloaded successfully ....." ,fg = "red" ,font = ('verdana' ,10 ,'bold' ),bg = "white" )
89+                                 self .dow_success .place (x = 10 ,y = 120 )
90+ 
91+                                 self .root .mainloop ()
92+ 
93+                                 
94+                         except :
95+                                 time .sleep (10 )
96+                                 messagebox .showerror ("Error" ,"Unable to Download Video | Something went wrong !!" )
97+ 
98+                 # ========================= End ============================== 
99+ 
100+         
101+         # =======================  Downloading Playlist ==================== 
102+         def  download_playlist (self ):
103+                 if  self .playlist_url .get () ==  "" :
104+                         messagebox .showerror ("Error" ,"Please Paste playlist URL" )
105+                 elif  'https://'  not  in self .playlist_url .get ():
106+                          messagebox .showerror ("Error" ,"Wrong playlist Url" )
107+                 elif  self .playlist_path .get () ==  "" :
108+                         messagebox .showerror ("Error" ,"Please provide Path" )
109+                 else :
110+                         try :
111+                                 self .url  =  self .playlist_url .get ()
112+                                 self .path  =  self .playlist_path .get ()
113+                                 self .playlist  =  Playlist (self .url )
114+                         
115+                                 self .root  =  tk .Tk ()
116+                                 self .root .geometry ('300x150' )
117+                                 self .root .maxsize (300 ,150 )
118+                                 self .root .minsize (300 ,150 )
119+                                 self .root .title ('Playlist Dowloading' )
120+                                 self .root ['bg' ] =  "white" 
121+ 
122+                                 
123+                                 self .start_downloading  =  Label (self .root ,text = "Playlist downloading ....." ,fg = "red" ,font = ('verdana' ,10 ,'bold' ),bg = "white" )
124+                                 self .start_downloading .place (x = 40 ,y = 10 )
125+ 
126+                                 for  self .video  in  self .playlist :
127+                                         self .video .streams .get_highest_resolution ().download (output_path  =  self .path ,filename = None )
128+                                 
129+                                 self .progress  =  Progressbar (self .root ,orient  =  HORIZONTAL ,length = 250 ,mode = 'determinate' )
130+                                 self .progress ['value' ] =  20 
131+                                 self .root .update_idletasks ()
132+                                 self .progress ['value' ] =  40 
133+                                 self .root .update_idletasks ()
134+                                 self .progress ['value' ] =  60 
135+                                 self .root .update_idletasks ()
136+                                 self .progress ['value' ] =  80 
137+                                 self .root .update_idletasks ()
138+                                 self .progress ['value' ] =  100 
139+                                 self .root .update_idletasks ()
140+                                 self .progress .place (x = 20 ,y = 40 )
141+ 
142+                                 self .dow_details  =  ScrolledText (self .root ,width = 30 ,height = 3 ,font = ('verdana' ,8 ,'bold' ))
143+                                 self .dow_details .place (x = 20 ,y = 70 )
144+                                 self .dow_details .insert (END ,f'{ self .playlist_path .get ()} \n  { self .video .title }  )
145+ 
146+                                 self .dow_success  =  Label (self .root ,text = "Playlist downloaded successfully ....." ,fg = "red" ,font = ('verdana' ,10 ,'bold' ),bg = "white" )
147+                                 self .dow_success .place (x = 10 ,y = 120 )
148+ 
149+                                 self .root .mainloop ()
150+ 
151+                                 
152+                         except :
153+                                 time .sleep (10 )
154+                                 messagebox .showerror ("Error" ,"Unable to Download Video | Something went wrong !!" )
155+ 
156+         # ========================= End ============================== 
157+ 
158+         # ======================== Clear ======================= 
159+ 
160+         def  Clear (self ):
161+                 self .video_url .delete (0 ,END )
162+                 self .video_path .delete (0 ,END )
163+                 self .playlist_url .delete (0 ,END )
164+                 self .playlist_path .delete (0 ,END )
165+         
166+         # ======================== Quit ======================= 
167+         def  Quit (self ):
168+                 self .root .destroy ()
169+                 
170+ 
171+ 
172+         # ==============================  Main Window ======================== 
173+         def  __init__ (self ):
174+                 self .root  =  tk .Tk ()
175+                 self .root .geometry ('500x270' )
176+                 self .root .maxsize (500 ,270 )
177+                 self .root .minsize (500 ,270 )
178+                 self .root ['bg' ]= "white" 
179+                 self .root .title ('Youtube Downloader' )
180+                 
181+                 self .l1  =  Label (self .root ,text = "Youtube Downloader" ,font = ('verdana' ,15 ,'bold' ),bg = "white" ,fg = "red" )
182+                 self .l1 .place (x = 130 ,y = 5 )
183+ 
184+                 self .design1  =  Label (self .root ,bg = "red" ,width = 20 )
185+                 self .design1 .place (x = 0 ,y = 45 )
186+ 
187+                 self .date  =  Label (self .root ,text = datetime .now (),font = ('verdana' ,10 ,'bold' ),bg = "white" )
188+                 self .date .place (x = 140 ,y = 45 )
189+ 
190+                 self .design2  =  Label (self .root ,bg = "red" ,width = 20 )
191+                 self .design2 .place (x = 360 ,y = 45 )
192+ 
193+                 self .design3  =  Label (self .root ,bg = "red" ,width = 3 ,height = 6 )
194+                 self .design3 .place (x = 242 ,y = 90 )
195+ 
196+                 self .yt_icon  =  ImageTk .PhotoImage (Image .open ('youtube.png' ))
197+                 self .logo  =  Label (self .root ,image = self .yt_icon ,bg = "white" )
198+                 self .logo .place (x = 220 ,y = 70 )
199+ 
200+                 
201+                 # ==================== Video ============================ 
202+ 
203+                 self .frame1  =  LabelFrame (self .root ,text = "Download Video" ,width = 180 ,height = 180 ,font = ('verdana' ,10 ,'bold' ),bg = "white" ,fg = "red" ,borderwidth = 5 ,relief = SUNKEN ,highlightcolor = "red" ,highlightbackground = "red" )
204+                 self .frame1 .place (x = 10 ,y = 80 ) 
205+ 
206+                 self .v_url  =  Label (self .frame1 ,text = "Paste url Here ..." ,font = ('verdana' ,10 ,'bold' ),bg = "white" )
207+                 self .v_url .place (x = 20 ,y = 2 )
208+ 
209+                 self .video_url  =  Entry (self .frame1 ,width = 24 ,relief = SUNKEN ,borderwidth = 2 ,bg = "red" ,fg = "white" )
210+                 self .video_url .place (x = 10 ,y = 30 )
211+ 
212+                 self .v_path  =  Label (self .frame1 ,text = "Select Path" ,font = ('verdana' ,10 ,'bold' ),bg = "white" )
213+                 self .v_path .place (x = 10 ,y = 60 )
214+ 
215+                 self .video_path  =  Entry (self .frame1 ,width = 15 ,relief = SUNKEN ,borderwidth = 2 ,bg = "red" ,fg = "white" )
216+                 self .video_path .place (x = 10 ,y = 90 )
217+ 
218+                 self .file  =  Button (self .frame1 ,text = "Browser" ,font = ('verdana' ,8 ,'bold' ),relief = RAISED ,bg = "white" ,command = self .select_v_path )
219+                 self .file .place (x = 105 ,y = 88 )
220+ 
221+                 self .download_video  =  Button (self .frame1 ,text = "Download" ,font = ('verdana' ,9 ,'bold' ),relief = RAISED ,bg = "white" ,borderwidth = 4 ,command = self .download_video )
222+                 self .download_video .place (x = 40 ,y = 125 )
223+ 
224+ 
225+                 # =============== Palylist ======================= 
226+                 
227+                 self .frame2  =  LabelFrame (self .root ,text = "Download Playlist" ,width = 180 ,height = 180 ,font = ('verdana' ,10 ,'bold' ),bg = "white" ,fg = "red" ,borderwidth = 5 ,relief = SUNKEN ,highlightcolor = "red" ,highlightbackground = "red" )
228+                 self .frame2 .place (x = 310 ,y = 80 ) 
229+ 
230+                 self .p_url  =  Label (self .frame2 ,text = "Paste url Here ..." ,font = ('verdana' ,10 ,'bold' ),bg = "white" )
231+                 self .p_url .place (x = 20 ,y = 2 )
232+ 
233+                 self .playlist_url  =  Entry (self .frame2 ,width = 24 ,relief = SUNKEN ,borderwidth = 2 ,bg = "red" ,fg = "white" )
234+                 self .playlist_url .place (x = 10 ,y = 30 )
235+ 
236+                 self .p_path  =  Label (self .frame2 ,text = "Select Path" ,font = ('verdana' ,10 ,'bold' ),bg = "white" )
237+                 self .p_path .place (x = 10 ,y = 60 )
238+ 
239+                 self .playlist_path  =  Entry (self .frame2 ,width = 15 ,relief = SUNKEN ,borderwidth = 2 ,bg = "red" ,fg = "white" )
240+                 self .playlist_path .place (x = 10 ,y = 90 )
241+ 
242+                 self .playlist_file  =  Button (self .frame2 ,text = "Browser" ,font = ('verdana' ,8 ,'bold' ),relief = RAISED ,bg = "white" ,command = self .select_p_path )
243+                 self .playlist_file .place (x = 105 ,y = 88 )
244+ 
245+                 self .download_playlist  =  Button (self .frame2 ,text = "Download" ,font = ('verdana' ,9 ,'bold' ),relief = RAISED ,bg = "white" ,borderwidth = 4 ,command = self .download_playlist )
246+                 self .download_playlist .place (x = 40 ,y = 125 )
247+ 
248+                 self .clear  =   Button (self .root ,text = "Clear" ,font = ('verdana' ,10 ,'bold' ),bg = "white" ,fg = "red" ,padx = 10 ,relief = RAISED ,borderwidth = 3 ,command = self .Clear )
249+                 self .clear .place (x = 220 ,y = 195 )
250+ 
251+                 self .quit  =   Button (self .root ,text = "Quit" ,font = ('verdana' ,10 ,'bold' ),bg = "red" ,fg = "white" ,padx = 15 ,relief = RAISED ,borderwidth = 3 ,command = self .Quit )
252+                 self .quit .place (x = 220 ,y = 230 )
253+ 
254+                 self .root .mainloop ()
255+ 
256+                 # =========================== End  ===================================== 
257+ 
258+ # ============== Calling =========== 
259+ 
260+ if  __name__  ==  '__main__' :
261+         YoutubeDownloader ()
262+ 
263+ == == == == == == == == == == == == == == == == == == 
0 commit comments