[youtube] only playable on yt and age gated

This commit is contained in:
Unknown 2020-10-07 04:19:08 +02:00
parent 6e728bc988
commit 9d9314cb66

View file

@ -1861,31 +1861,60 @@ def extract_player_response(player_response, video_id):
embed_webpage = None embed_webpage = None
if (self._og_search_property('restrictions:age', video_webpage, default=None) == '18+' if (self._og_search_property('restrictions:age', video_webpage, default=None) == '18+'
or re.search(r'player-age-gate-content">', video_webpage) is not None): or re.search(r'player-age-gate-content">', video_webpage) is not None):
cookie_keys = self._get_cookies('https://www.youtube.com').keys()
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 url = proto + '://www.youtube.com/embed/%s' % video_id
embed_webpage = self._download_webpage(url, video_id, 'Downloading embed webpage') embed_webpage = self._download_webpage(url, video_id, 'Downloading embed webpage')
data = compat_urllib_parse_urlencode({ # check if video is only playable on youtube - if so it requires auth (cookies)
'video_id': video_id, if re.search(r'player-unavailable">', embed_webpage) is not None:
'eurl': 'https://youtube.googleapis.com/v/' + video_id, if ({'VISITOR_INFO1_LIVE', 'HSID', 'SSID', 'SID'} <= cookie_keys
'sts': self._search_regex( or {'VISITOR_INFO1_LIVE', '__Secure-3PSID', 'LOGIN_INFO'} <= cookie_keys):
r'"sts"\s*:\s*(\d+)', embed_webpage, 'sts', default=''), age_gate = False
}) # Try looking directly into the video webpage
video_info_url = proto + '://www.youtube.com/get_video_info?' + data ytplayer_config = self._get_ytplayer_config(video_id, video_webpage)
try: if ytplayer_config:
video_info_webpage = self._download_webpage( args = ytplayer_config['args']
video_info_url, video_id, if args.get('url_encoded_fmt_stream_map') or args.get('hlsvp'):
note='Refetching age-gated info webpage', # Convert to the same format returned by compat_parse_qs
errnote='unable to download video info webpage') video_info = dict((k, [v]) for k, v in args.items())
except ExtractorError: add_dash_mpd(video_info)
video_info_webpage = None # Rental video is not rented but preview is available (e.g.
if video_info_webpage: # https://www.youtube.com/watch?v=yYr8q0y5Jfg,
video_info = compat_parse_qs(video_info_webpage) # https://github.com/ytdl-org/youtube-dl/issues/10532)
pl_response = video_info.get('player_response', [None])[0] if not video_info and args.get('ypc_vid'):
player_response = extract_player_response(pl_response, video_id) return self.url_result(
add_dash_mpd(video_info) args['ypc_vid'], YoutubeIE.ie_key(), video_id=args['ypc_vid'])
view_count = extract_view_count(video_info) if args.get('livestream') == '1' or args.get('live_playback') == 1:
is_live = True
if not player_response:
player_response = extract_player_response(args.get('player_response'), video_id)
if not video_info or self._downloader.params.get('youtube_include_dash_manifest', True):
add_dash_mpd_pr(player_response)
else:
raise ExtractorError('Video is age restricted and only playable on Youtube. Requires cookies!', expected=True)
else:
data = compat_urllib_parse_urlencode({
'video_id': video_id,
'eurl': 'https://youtube.googleapis.com/v/' + video_id,
'sts': self._search_regex(
r'"sts"\s*:\s*(\d+)', embed_webpage, 'sts', default=''),
})
video_info_url = proto + '://www.youtube.com/get_video_info?' + data
try:
video_info_webpage = self._download_webpage(
video_info_url, video_id,
note='Refetching age-gated info webpage',
errnote='unable to download video info webpage')
except ExtractorError:
video_info_webpage = None
if video_info_webpage:
video_info = compat_parse_qs(video_info_webpage)
pl_response = video_info.get('player_response', [None])[0]
player_response = extract_player_response(pl_response, video_id)
add_dash_mpd(video_info)
view_count = extract_view_count(video_info)
else: else:
age_gate = False age_gate = False
# Try looking directly into the video webpage # Try looking directly into the video webpage