[youtube] Improve ytplayer.config extraction

pull/8/head
Sergey M․ 9 years ago
parent 5ae17037a3
commit a72778d364

@ -891,22 +891,24 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
return {} return {}
return sub_lang_list return sub_lang_list
def _get_ytplayer_config(self, webpage): def _get_ytplayer_config(self, video_id, webpage):
patterns = [ patterns = (
r';ytplayer\.config\s*=\s*({.*?});ytplayer', r';ytplayer\.config\s*=\s*({.+?});ytplayer',
r';ytplayer\.config\s*=\s*({.*?});', r';ytplayer\.config\s*=\s*({.+?});',
] )
config = self._search_regex(patterns, webpage, 'ytconfig.player', default=None) config = self._search_regex(
if config is not None: patterns, webpage, 'ytplayer.config', default=None)
return json.loads(uppercase_escape(config)) if config:
return self._parse_json(
uppercase_escape(config), video_id, fatal=False)
def _get_automatic_captions(self, video_id, webpage): def _get_automatic_captions(self, video_id, webpage):
"""We need the webpage for getting the captions url, pass it as an """We need the webpage for getting the captions url, pass it as an
argument to speed up the process.""" argument to speed up the process."""
self.to_screen('%s: Looking for automatic captions' % video_id) self.to_screen('%s: Looking for automatic captions' % video_id)
player_config = self._get_ytplayer_config(webpage) player_config = self._get_ytplayer_config(video_id, webpage)
err_msg = 'Couldn\'t find automatic captions for %s' % video_id err_msg = 'Couldn\'t find automatic captions for %s' % video_id
if player_config is None: if not player_config:
self._downloader.report_warning(err_msg) self._downloader.report_warning(err_msg)
return {} return {}
try: try:
@ -1115,8 +1117,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
age_gate = False age_gate = False
video_info = None video_info = None
# Try looking directly into the video webpage # Try looking directly into the video webpage
ytplayer_config = self._get_ytplayer_config(video_webpage) ytplayer_config = self._get_ytplayer_config(video_id, video_webpage)
if ytplayer_config is not None: if ytplayer_config:
args = ytplayer_config['args'] args = ytplayer_config['args']
if args.get('url_encoded_fmt_stream_map'): if args.get('url_encoded_fmt_stream_map'):
# Convert to the same format returned by compat_parse_qs # Convert to the same format returned by compat_parse_qs

Loading…
Cancel
Save