Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/archiveorg.py (Python)

Code before:
        elif not isinstance(res, list) or len(res) != 0:
            self.report_warning('Error while parsing CDX API response' + bug_reports_message())

    def _extract_webpage_title(self, webpage):
        page_title = self._html_extract_title(webpage, default='')
        # YouTube video pages appear to always have either 'YouTube -' as prefix or '- YouTube' as suffix.
        return self._html_search_regex(
            r'(?:YouTube\s*-\s*(.*)$)|(?:(.*)\s*-\s*YouTube$)',
            page_title, 'title', default='')

    def _extract_metadata(self, video_id, webpage):
        search_meta = ((lambda x: self._html_search_meta(x, webpage, default=None)) if webpage else (lambda x: None))
        player_response = self._search_json(
            self._YT_INITIAL_PLAYER_RESPONSE_RE, webpage, 'initial player response',
            video_id, default={})
        initial_data = self._search_json(
            self._YT_INITIAL_DATA_RE, webpage, 'initial data', video_id, default={})

        ytcfg = {}
        for j in re.findall(r'yt\.setConfig\(\s*(?P<json>{\s*(?s:.+?)\s*})\s*\);', webpage):  # ~June 2010
            ytcfg.update(self._parse_json(j, video_id, fatal=False, ignore_extra=True, transform_source=js_to_json, errnote='') or {})

        # XXX: this also may contain a 'ptchn' key
        player_config = (
            self._search_json(
                r'(?:yt.playerConfig|ytplayer.config|swfConfig)\s*=',
                webpage, 'player config', video_id, default=None)
            or ytcfg.get('PLAYER_CONFIG') or {})

        # XXX: this may also contain a 'creator' key.
        swf_args = self._search_json(r'swfArgs\s*=\s*', webpage, 'swf config', video_id, default={})
        if swf_args and not traverse_obj(player_config, ('args',)):
            player_config['args'] = swf_args

        if not player_response:
            # April 2020
            player_response = self._parse_json(
                traverse_obj(player_config, ('args', 'player_response')) or '{}', video_id, fatal=False)

        initial_data_video = traverse_obj(
            initial_data, ('contents', 'twoColumnWatchNextResults', 'results', 'results', 'contents', ..., 'videoPrimaryInfoRenderer'),
            expected_type=dict, get_all=False, default={})

        video_details = traverse_obj(
            player_response, 'videoDetails', expected_type=dict, get_all=False, default={})

        microformats = traverse_obj(
            player_response, ('microformat', 'playerMicroformatRenderer'), expected_type=dict, get_all=False, default={})

        video_title = (
            video_details.get('title')

Review comment (suggestion):
```suggestion
                r'(?:yt\.playerConfig|ytplayer\.config|swfConfig)\s*=',
```

Code after:
        elif not isinstance(res, list) or len(res) != 0:
            self.report_warning('Error while parsing CDX API response' + bug_reports_message())

    def _extract_webpage_title(self, webpage):
        page_title = self._html_extract_title(webpage, default='')
        # YouTube video pages appear to always have either 'YouTube -' as prefix or '- YouTube' as suffix.
        return self._html_search_regex(
            r'(?:YouTube\s*-\s*(.*)$)|(?:(.*)\s*-\s*YouTube$)',
            page_title, 'title', default='')

    def _extract_metadata(self, video_id, webpage):
        search_meta = ((lambda x: self._html_search_meta(x, webpage, default=None)) if webpage else (lambda x: None))
        player_response = self._search_json(
            self._YT_INITIAL_PLAYER_RESPONSE_RE, webpage, 'initial player response',
            video_id, default={})
        initial_data = self._search_json(
            self._YT_INITIAL_DATA_RE, webpage, 'initial data', video_id, default={})

        ytcfg = {}
        for j in re.findall(r'yt\.setConfig\(\s*(?P<json>{\s*(?s:.+?)\s*})\s*\);', webpage):  # ~June 2010
            ytcfg.update(self._parse_json(j, video_id, fatal=False, ignore_extra=True, transform_source=js_to_json, errnote='') or {})

        # XXX: this also may contain a 'ptchn' key
        player_config = (
            self._search_json(
                r'(?:yt\.playerConfig|ytplayer\.config|swfConfig)\s*=',
                webpage, 'player config', video_id, default=None)
            or ytcfg.get('PLAYER_CONFIG') or {})

        # XXX: this may also contain a 'creator' key.
        swf_args = self._search_json(r'swfArgs\s*=', webpage, 'swf config', video_id, default={})
        if swf_args and not traverse_obj(player_config, ('args',)):
            player_config['args'] = swf_args

        if not player_response:
            # April 2020
            player_response = self._parse_json(
                traverse_obj(player_config, ('args', 'player_response')) or '{}', video_id, fatal=False)

        initial_data_video = traverse_obj(
            initial_data, ('contents', 'twoColumnWatchNextResults', 'results', 'results', 'contents', ..., 'videoPrimaryInfoRenderer'),
            expected_type=dict, get_all=False, default={})

        video_details = traverse_obj(
            player_response, 'videoDetails', expected_type=dict, get_all=False, default={})

        microformats = traverse_obj(
            player_response, ('microformat', 'playerMicroformatRenderer'), expected_type=dict, get_all=False, default={})

        video_title = (
            video_details.get('title')