@@ -220,19 +220,27 @@ def _real_extract(self, url):
220
220
'id' : video_id ,
221
221
'export' : 'download' ,
222
222
})
223
- urlh = self ._request_webpage (
224
- source_url , video_id , note = 'Requesting source file' ,
225
- errnote = 'Unable to request source file' , fatal = False )
223
+
224
+ def request_source_file (source_url , kind ):
225
+ return self ._request_webpage (
226
+ source_url , video_id , note = 'Requesting %s file' % kind ,
227
+ errnote = 'Unable to request %s file' % kind , fatal = False )
228
+ urlh = request_source_file (source_url , 'source' )
226
229
if urlh :
227
- def add_source_format (src_url ):
230
+ def add_source_format (urlh ):
228
231
formats .append ({
229
- 'url' : src_url ,
232
+ # Use redirect URLs as download URLs in order to calculate
233
+ # correct cookies in _calc_cookies.
234
+ # Using original URLs may result in redirect loop due to
235
+ # google.com's cookies mistakenly used for googleusercontent.com
236
+ # redirect URLs (see #23919).
237
+ 'url' : urlh .geturl (),
230
238
'ext' : determine_ext (title , 'mp4' ).lower (),
231
239
'format_id' : 'source' ,
232
240
'quality' : 1 ,
233
241
})
234
242
if urlh .headers .get ('Content-Disposition' ):
235
- add_source_format (source_url )
243
+ add_source_format (urlh )
236
244
else :
237
245
confirmation_webpage = self ._webpage_read_content (
238
246
urlh , url , video_id , note = 'Downloading confirmation page' ,
@@ -242,9 +250,12 @@ def add_source_format(src_url):
242
250
r'confirm=([^&"\']+)' , confirmation_webpage ,
243
251
'confirmation code' , fatal = False )
244
252
if confirm :
245
- add_source_format ( update_url_query (source_url , {
253
+ confirmed_source_url = update_url_query (source_url , {
246
254
'confirm' : confirm ,
247
- }))
255
+ })
256
+ urlh = request_source_file (confirmed_source_url , 'confirmed source' )
257
+ if urlh and urlh .headers .get ('Content-Disposition' ):
258
+ add_source_format (urlh )
248
259
249
260
if not formats :
250
261
reason = self ._search_regex (
0 commit comments