@@ -131,19 +131,19 @@ def main():
131131 start = 0
132132 end = 0
133133 path = "playlist"
134- # url = input("Enter the Youtube-url\n")
135- # name = input("Enter the name for the video\n")
136- # name = name + ".mp4"
137134
138135 parser = argparse .ArgumentParser ()
139- parser .add_argument ('-d ' , '--url' , nargs = '?' ,
136+ parser .add_argument ('-u ' , '--url' , nargs = '?' ,
140137 help = "Complete download link of the playlist" , type = str )
141138 parser .add_argument ('-l' , '--list' , nargs = '?' ,
142139 help = "List id of the playlist" , type = str )
143140 parser .add_argument ('-s' , '--start' , nargs = '?' ,
144141 help = "Start no. of playlist" , type = int )
145142 parser .add_argument ('-e' , '--end' , nargs = '?' ,
146143 help = "End no. of playlist" , type = int )
144+ parser .add_argument ("-d" , "--driver" , type = str , default = "phantomjs" ,
145+ help = "which driver to use [option: phantomjs, firefox, chrome]" )
146+
147147 args = parser .parse_args ()
148148
149149 if args .url :
@@ -160,54 +160,55 @@ def main():
160160
161161 try :
162162
163- # Phantom JS
163+ 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 );
164175
165- driver = webdriver .PhantomJS (
166- executable_path = r'C:\Users\ankit\Downloads\phantomjs-2.1.1-windows (1)\phantomjs-2.1.1-windows\bin\phantomjs.exe' )
167176 driver .set_window_size (1120 , 550 )
168177
169- # FireFox
170-
171- # binary = FirefoxBinary(
172- # 'C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')
173- # driver = webdriver.Firefox(firefox_binary=binary)
174- # driver.set_window_size(1120, 550)
175-
176178 driver .get (url )
177179 WebDriverWait (driver , 10000 ).until (
178180 EC .presence_of_element_located (
179- (By .CSS_SELECTOR , ".pl-header-title " )
181+ (By .CSS_SELECTOR , ".yt-formatted-string " )
180182 )
181183 )
182184
183185 soup = BeautifulSoup (driver .page_source , 'html.parser' )
184186 path = soup .find (
185- "h1 " , class_ = "pl-header-title " ).string . replace ( ' \n ' , '' ). replace ( ' ' , '' ). replace ( ',' , '' ). replace ( '.' , '' ). replace ( ':' , '' )
187+ "a " , class_ = "yt-formatted-string " ).string
186188
187189 _urls = soup .find_all (
188- "a " , class_ = "pl- video-title-link " )
190+ "ytd-playlist-video-renderer " , class_ = "ytd-playlist- video-list-renderer " )
189191
190192 totalVideos = len (_urls )
191193 if end == 0 :
192194 end = totalVideos
193195
194196 print ("There are total of " + str (totalVideos ) + " Videos in the playlist" )
195197
196- if not os .path .exists (path ):
197- os .system ('mkdir %s' % path )
198+ if not os .path .exists (r'"' + path + '"' ):
199+ os .system ('mkdir %s' % r'"' + path + '"' )
198200
199201 for i in range (start , end ):
200202
201203 _url = _urls [i ]
202204
203- _name = _url .string .replace ('\n ' , '' ).replace (
204- ' ' , '' ).replace (',' , '' ).replace ('.' , '' ).replace (':' , '' )
205-
205+ _name = _url .find ("h3" ).find ("span" ).string .replace ('\n ' , '' ).replace (
206+ ' ' , '' )
206207 _name += '.mp4'
207208
208- _url = prefix + _url .get ("href" )
209-
210- driver . get ( "http://en.savefrom.net" )
209+ _url = prefix + _url .find ( "a" ). get ("href" )
210+ driver . get ( "https://en.savefrom.net" )
211+ sleep ( 1 )
211212 WebDriverWait (driver , 10000 ).until (
212213 EC .presence_of_element_located (
213214 (By .CSS_SELECTOR , "#sf_url" )
@@ -238,7 +239,7 @@ def main():
238239 "a" , class_ = "link link-download subname ga_track_events download-icon" )
239240 url_parse = click .get ("href" )
240241 print (str (i + 1 ) + "- Downloading " + _name )
241- with open (path + "\\ " + _name , 'wb' ) as out_file :
242+ with open (path + "// " + _name , 'wb' ) as out_file :
242243 with urlopen (url_parse ) as fp :
243244 info = fp .info ()
244245 if 'Content-Length' in info :
0 commit comments