From a72778d364022612ba88bdfd9affef0d7b0ca864 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sergey=20M=E2=80=A4?= Date: Mon, 23 Nov 2015 21:00:06 +0600 Subject: [PATCH] [youtube] Improve ytplayer.config extraction --- youtube_dl/extractor/youtube.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py index 1580c54fe..052f6922a 100644 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@ -891,22 +891,24 @@ class YoutubeIE(YoutubeBaseInfoExtractor): return {} return sub_lang_list - def _get_ytplayer_config(self, webpage): - patterns = [ - r';ytplayer\.config\s*=\s*({.*?});ytplayer', - r';ytplayer\.config\s*=\s*({.*?});', - ] - config = self._search_regex(patterns, webpage, 'ytconfig.player', default=None) - if config is not None: - return json.loads(uppercase_escape(config)) + def _get_ytplayer_config(self, video_id, webpage): + patterns = ( + r';ytplayer\.config\s*=\s*({.+?});ytplayer', + r';ytplayer\.config\s*=\s*({.+?});', + ) + config = self._search_regex( + patterns, webpage, 'ytplayer.config', default=None) + if config: + return self._parse_json( + uppercase_escape(config), video_id, fatal=False) def _get_automatic_captions(self, video_id, webpage): """We need the webpage for getting the captions url, pass it as an argument to speed up the process.""" 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 - if player_config is None: + if not player_config: self._downloader.report_warning(err_msg) return {} try: @@ -1115,8 +1117,8 @@ class YoutubeIE(YoutubeBaseInfoExtractor): age_gate = False video_info = None # Try looking directly into the video webpage - ytplayer_config = self._get_ytplayer_config(video_webpage) - if ytplayer_config is not None: + ytplayer_config = self._get_ytplayer_config(video_id, video_webpage) + if ytplayer_config: args = ytplayer_config['args'] if args.get('url_encoded_fmt_stream_map'): # Convert to the same format returned by compat_parse_qs -- 2.22.2