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

Code before:
            r_id = traverse_obj(video_info, (
                'video', ('videoRefID', 'videoID'), {str}, any, {require('reference ID')}))
            if not r_id.isdecimal():
                r_id = f'ref:{r_id}'

            return {
                **metadata,
                '_type': 'url_transparent',
                'url': smuggle_url(
                    self.BRIGHTCOVE_URL_TEMPLATE % (p_id, r_id),
                    {'geo_countries': ['JP']}),
                'ie_key': 'BrightcoveNew',
            }

        ref_id = video_info['streaks']['videoRefID']
        if not ref_id.startswith('ref:'):
            ref_id = f'ref:{ref_id}'

        return {
            **self._extract_from_streaks_api(video_info['streaks']['projectID'], ref_id, {
                'Origin': 'https://tver.jp',
                'Referer': 'https://tver.jp/',
            }),
            **metadata,
            'id': video_id,
        }

    def _format_broadcast_date(self, onair_label):
        """
        Extracts the broadcast date from the onair label

        Truth to be said, we cannot be sure or guarantee that the broadcast date is correct
        as TVer doesn't really have consistent date format for the broadcast date.
        At best we can only assume the following:
        - If there is only year, this mean the broadcast is old.
        - If there is only month and day, this mean the broadcast is recent within the current year or the previous year.

        :param onair_label: The onair label string
        :return: A dictionary containing the formatted broadcast date or an empty dictionary if the date is not found

        """
        if not onair_label:
            return {}

        match = re.search(
            pattern=r'(?:(?P<year>\d{4})年)|(?:(?P<month>\d{1,2})\D(?P<day>\d{1,2})\D)',
            string=onair_label,
        )

        if not match:
            return {}

Review comment (refactor):
I removed the brightcove method and moved the code back into `_real_extract` because A) it wasn't that much code and B) here we also want to return `'_old_archive_ids'` with the brightcove id if possible

Code after:

        brightcove_id = traverse_obj(video_info, ('video', ('videoRefID', 'videoID'), {str}, any))
        if brightcove_id and not brightcove_id.isdecimal():
            brightcove_id = f'ref:{brightcove_id}'

        streaks_id = traverse_obj(video_info, ('streaks', 'videoRefID', {str}))
        if streaks_id and not streaks_id.startswith('ref:'):
            streaks_id = f'ref:{streaks_id}'

        # Deprecated Brightcove extraction reachable w/extractor-arg or fallback; errors are expected
        if backend == 'brightcove' or not streaks_id:
            if backend != 'brightcove':
                self.report_warning(
                    'No STREAKS ID found; falling back to Brightcove extraction', video_id=video_id)
            if not brightcove_id:
                raise ExtractorError('Unable to extract brightcove reference ID', expected=True)
            account_id = traverse_obj(video_info, (
                'video', 'accountID', {str}, {require('brightcove account ID', expected=True)}))
            return {
                **metadata,
                '_type': 'url_transparent',
                'url': smuggle_url(
                    self.BRIGHTCOVE_URL_TEMPLATE % (account_id, brightcove_id),
                    {'geo_countries': ['JP']}),
                'ie_key': 'BrightcoveNew',
            }

        return {
            **self._extract_from_streaks_api(video_info['streaks']['projectID'], streaks_id, {
                'Origin': 'https://tver.jp',
                'Referer': 'https://tver.jp/',
            }),
            **metadata,
            'id': video_id,
            '_old_archive_ids': [make_archive_id('BrightcoveNew', brightcove_id)] if brightcove_id else None,
        }