@@ -131,6 +131,8 @@ def main():
131
131
start = 0
132
132
end = 0
133
133
path = "playlist"
134
+ driver = ""
135
+ system = sys .platform
134
136
135
137
parser = argparse .ArgumentParser ()
136
138
parser .add_argument ('-u' , '--url' , nargs = '?' ,
@@ -142,7 +144,7 @@ def main():
142
144
parser .add_argument ('-e' , '--end' , nargs = '?' ,
143
145
help = "End no. of playlist" , type = int )
144
146
parser .add_argument ("-d" , "--driver" , type = str , default = "phantomjs" ,
145
- help = "which driver to use [option: phantomjs, firefox, chrome]" )
147
+ help = "which driver to use [option: phantomjs, firefox, chrome]" )
146
148
147
149
args = parser .parse_args ()
148
150
@@ -161,17 +163,30 @@ def main():
161
163
try :
162
164
163
165
choice = args .driver
164
- driver = ""
165
- if choice == "firefox" :
166
- binary = FirefoxBinary ('firefox' )
167
- driver = webdriver .Firefox (firefox_binary = binary )
168
- elif choice == "chrome" :
169
- driver = webdriver .Chrome ();
170
- elif choice == "phantomjs" :
171
- driver = webdriver .PhantomJS ()
172
- else :
173
- print ("Invalid Choice" );
174
- sys .exit (1 );
166
+ if system == "linux" or system == "linux2" :
167
+ if choice == "firefox" :
168
+ binary = FirefoxBinary ('firefox' )
169
+ driver = webdriver .Firefox (firefox_binary = binary )
170
+ elif choice == "chrome" :
171
+ driver = webdriver .Chrome ()
172
+ elif choice == "phantomjs" :
173
+ driver = webdriver .PhantomJS ()
174
+ else :
175
+ print ("Invalid Choice" )
176
+ sys .exit (1 )
177
+
178
+ elif system == "win32" :
179
+ if choice == "firefox" :
180
+ binary = FirefoxBinary ('firefox.exe' )
181
+ driver = webdriver .Firefox (firefox_binary = binary )
182
+ elif choice == "chrome" :
183
+ driver = webdriver .Chrome ('chromedriver.exe' )
184
+ elif choice == "phantomjs" :
185
+ driver = webdriver .PhantomJS (
186
+ executable_path = r'phantomjs.exe' )
187
+ else :
188
+ print ("Invalid Choice" )
189
+ sys .exit (1 )
175
190
176
191
driver .set_window_size (1120 , 550 )
177
192
@@ -184,8 +199,8 @@ def main():
184
199
185
200
soup = BeautifulSoup (driver .page_source , 'html.parser' )
186
201
path = soup .find (
187
- "a" , class_ = "yt-formatted-string" ).string
188
-
202
+ "a" , class_ = "yt-formatted-string" ).string . replace ( '|' , '-' )
203
+ print ( path )
189
204
_urls = soup .find_all (
190
205
"ytd-playlist-video-renderer" , class_ = "ytd-playlist-video-list-renderer" )
191
206
@@ -195,15 +210,17 @@ def main():
195
210
196
211
print ("There are total of " + str (totalVideos ) + " Videos in the playlist" )
197
212
198
- if not os .path .exists (r'"' + path + '"' ):
199
- os .system ('mkdir %s' % r'"' + path + '"' )
213
+ if not os .path .exists (r'"' + path + '"' ):
214
+ os .system ('mkdir %s' % r'"' + path + '"' )
215
+ # path = os.path.abspath(path)
216
+ # print(path)
200
217
201
218
for i in range (start , end ):
202
219
203
220
_url = _urls [i ]
204
221
205
222
_name = _url .find ("h3" ).find ("span" ).string .replace ('\n ' , '' ).replace (
206
- ' ' , '' )
223
+ ' ' , '' ). replace ( '|' , '-' )
207
224
_name += '.mp4'
208
225
209
226
_url = prefix + _url .find ("a" ).get ("href" )
@@ -239,7 +256,7 @@ def main():
239
256
"a" , class_ = "link link-download subname ga_track_events download-icon" )
240
257
url_parse = click .get ("href" )
241
258
print (str (i + 1 ) + "- Downloading " + _name )
242
- with open (path + "// " + _name , 'wb' ) as out_file :
259
+ with open (path + "\\ " + _name , 'wb' ) as out_file :
243
260
with urlopen (url_parse ) as fp :
244
261
info = fp .info ()
245
262
if 'Content-Length' in info :
@@ -262,9 +279,9 @@ def main():
262
279
print ("\n " )
263
280
print ("Successfully download " + _name )
264
281
sys .stdout .write ("\a " )
282
+ driver .quit ()
265
283
except Exception as e :
266
284
print (e )
267
- driver .quit ()
268
285
269
286
270
287
if __name__ == '__main__' :
0 commit comments