[youtube] Fix videos with age gate and encrypted signatures

The `sts` value is available on the embed webpage, get it from there.

Fixes #4108.
This commit is contained in:
Cédric Luthi 2014-12-29 22:58:14 +01:00
parent 5435d7af91
commit beb95e7781

View file

@ -766,11 +766,13 @@ def _real_extract(self, url):
age_gate = True age_gate = True
# We simulate the access to the video from www.youtube.com/v/{video_id} # We simulate the access to the video from www.youtube.com/v/{video_id}
# this can be viewed without login into Youtube # this can be viewed without login into Youtube
url = proto + '://www.youtube.com/embed/%s' % video_id
embed_webpage = self._download_webpage(url, video_id, 'Downloading embed webpage')
data = compat_urllib_parse.urlencode({ data = compat_urllib_parse.urlencode({
'video_id': video_id, 'video_id': video_id,
'eurl': 'https://youtube.googleapis.com/v/' + video_id, 'eurl': 'https://youtube.googleapis.com/v/' + video_id,
'sts': self._search_regex( 'sts': self._search_regex(
r'"sts"\s*:\s*(\d+)', video_webpage, 'sts', default=''), r'"sts"\s*:\s*(\d+)', embed_webpage, 'sts', default=''),
}) })
video_info_url = proto + '://www.youtube.com/get_video_info?' + data video_info_url = proto + '://www.youtube.com/get_video_info?' + data
video_info_webpage = self._download_webpage( video_info_webpage = self._download_webpage(
@ -968,11 +970,10 @@ def _map_to_format_list(urlmap):
elif 's' in url_data: elif 's' in url_data:
encrypted_sig = url_data['s'][0] encrypted_sig = url_data['s'][0]
if not age_gate: jsplayer_url_json = self._search_regex(
jsplayer_url_json = self._search_regex( r'"assets":.+?"js":\s*("[^"]+")',
r'"assets":.+?"js":\s*("[^"]+")', embed_webpage if age_gate else video_webpage, 'JS player URL')
video_webpage, 'JS player URL') player_url = json.loads(jsplayer_url_json)
player_url = json.loads(jsplayer_url_json)
if player_url is None: if player_url is None:
player_url_json = self._search_regex( player_url_json = self._search_regex(
r'ytplayer\.config.*?"url"\s*:\s*("[^"]+")', r'ytplayer\.config.*?"url"\s*:\s*("[^"]+")',