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

Code before:
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        page = self._download_webpage(url, video_id)
        meta = self._search_json('window.app=', page, 'episode info', video_id)

        episode = traverse_obj(meta, ('falcorCache', 'catalog', 'episode', video_id, 'value'))

        episode_meta = traverse_obj(episode, {
            'categories': 'keywords',
            'id': 'content_id',
            'description': ('description', 0, 'value'),
            'timestamp': ('created_at', {unified_timestamp}),
            'release_timestamp': ('pub_date', {unified_timestamp}),
            'duration': ('tv_episode_info', 'duration'),
            'episode_number': ('tv_episode_info', 'episode_number'),
            'series': ('custom_data', 'program_name'),
        })

        tf_url = urljoin(
            url,
            self._search_regex(r'<script src=["\'](/assets/tf\.[^"\']+\.js)["\']', page, 'stream API config')
        )
        tf_js = self._download_webpage(tf_url, video_id, note='Downloading stream API config')
        video_url = self._search_regex(r'videoPlaybackUrl: *[\'"]([^\'"]+)[\'"]', tf_js, 'stream API url')
        api_key = self._search_regex(r'api_key: *[\'"]([^\'"]+)[\'"]', tf_js, 'stream API key')

        try:
            source_meta = self._download_json(f'{video_url}ref:{video_id}', video_id,
                                              headers={'X-Streaks-Api-Key': api_key},
                                              note='Downloading stream metadata')
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 403:
                self.raise_geo_restricted(countries=['JP'])
            raise

        formats = []
        subs = []
        for i in traverse_obj(source_meta, ('sources', ..., 'src')):
            format, sub = self._extract_m3u8_formats_and_subtitles(i, video_id)
            formats.extend(format)
            subs.extend(sub)

        return {
            'title': get_element_text_and_html_by_tag('h3', page)[0],
            'episode': traverse_obj(episode, ('title', lambda _, v: not v.get('is_phonetic'), 'value'), get_all=False),
            **episode_meta,
            'formats': formats,
            'subtitles': sub,

Review comment (suggestion):
I'd write it like this
```suggestion
        tf_path = self._search_regex(
            r'<script[^>]+src=["\'](/assets/tf\.[^"\']+\.js)["\']', page, 'stream API config')
        tf_js = self._download_webpage(urljoin(url, tf_path), video_id, note='Downloading stream API config')
```
but your way is OK too if you do this
```suggestion
        tf_url = urljoin(
            url,
            self._search_regex(r'<script[^>]+src=["\'](/assets/tf\.[^"\']+\.js)["\']', page, 'stream API config'))
        tf_js = self._download_webpage(tf_url, video_id, note='Downloading stream API config')
```

Code after:
            'categories': 'count:11',
            'episode_number': 3,
            'timestamp': 1690522538,
            'description': 'md5:2b796341af1ef772034133174ba4a895',
            'series': 'VIVANT',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        meta = self._search_json(r'window\.app\s*=', webpage, 'episode info', video_id, fatal=False)
        episode = traverse_obj(meta, ('falcorCache', 'catalog', 'episode', video_id, 'value'))

        tf_path = self._search_regex(
            r'<script[^>]+src=["\'](/assets/tf\.[^"\']+\.js)["\']', webpage, 'stream API config')
        tf_js = self._download_webpage(urljoin(url, tf_path), video_id, note='Downloading stream API config')
        video_url = self._search_regex(r'videoPlaybackUrl:\s*[\'"]([^\'"]+)[\'"]', tf_js, 'stream API url')
        api_key = self._search_regex(r'api_key:\s*[\'"]([^\'"]+)[\'"]', tf_js, 'stream API key')

        try:
            source_meta = self._download_json(f'{video_url}ref:{video_id}', video_id,
                                              headers={'X-Streaks-Api-Key': api_key},
                                              note='Downloading stream metadata')
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 403:
                self.raise_geo_restricted(countries=['JP'])
            raise

        formats, subtitles = [], {}
        for src in traverse_obj(source_meta, ('sources', ..., 'src')):
            fmts, subs = self._extract_m3u8_formats_and_subtitles(src, video_id, fatal=False)
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)

        return {
            'title': try_call(lambda: clean_html(get_element_text_and_html_by_tag('h3', webpage)[0])),
            'id': video_id,
            **traverse_obj(episode, {
                'categories': ('keywords', {list}),
                'id': ('content_id', {str}),
                'description': ('description', 0, 'value'),
                'timestamp': ('created_at', {unified_timestamp}),
                'release_timestamp': ('pub_date', {unified_timestamp}),
                'duration': ('tv_episode_info', 'duration', {int_or_none}),
                'episode_number': ('tv_episode_info', 'episode_number', {int_or_none}),
                'episode': ('title', lambda _, v: not v.get('is_phonetic'), 'value'),
                'series': ('custom_data', 'program_name'),
            }, get_all=False),
            'formats': formats,
            'subtitles': subtitles,