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

Code before:
            'release_timestamp': 1743512400,
            'series': 'Star Trek: The Original Series',
            'series_id': 'star-trek-the-original-series',
            'thumbnail': r're:https?://.+\.(?:jpg|png)',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        page_props = traverse_obj(self._search_nextjs_data(
            webpage, video_id), ('props', 'pageProps', {dict}), default={})
        video_data = traverse_obj(page_props, ('video', 'data', {dict}))
        if youtube_id := video_data.get('youtube_video_id'):
            return self.url_result(youtube_id, 'Youtube')

        series_id = traverse_obj(video_data, (
            'series_and_movies', ..., 'series_or_movie', 'slug', {str}, any))

        subtitles = {}
        if sub_url := traverse_obj(video_data, ('legacy_subtitle_file', {url_or_none})):
            subtitles.setdefault('en', []).append({
                'ext': determine_ext(sub_url),
                'url': sub_url,
            })

        return {
            'id': video_id,
            'series': traverse_obj(page_props, (
                'queried', 'header', 'tab3', 'slices', ..., 'items',
                lambda _, v: v['link']['slug'] == series_id, 'link_copy', {str}, any)),
            'series_id': series_id,
            'subtitles': subtitles,
            **traverse_obj(video_data, {
                'title': ('title', ..., 'text', {clean_html}, any),
                'alt_title': ('subhead', ..., 'text', {clean_html}, any),
                'categories': ('category', 'data', 'category_name', {str.upper}, all),
                'description': ('slices', ..., 'primary', 'content', ..., 'text', {clean_html}, any),
                'release_timestamp': ('published', {parse_iso8601}),
                'thumbnail': ('poster_frame', 'url', {url_or_none}, {update_url(query=None)}),
                'url': ('legacy_video_url', {url_or_none}),
            }),
        }


Review comment (suggestion):
If we're hardcoding the language then this is a good candidate for `utils.traversal.subs_list_to_dict`.

(btw, core code already calls `determine_ext` on the url if there isn't an `ext` field present)

You could even inline this in the return
```suggestion
        subtitles = traverse_obj(video_data, (
            {'url': 'legacy_subtitle_file'}, all, {subs_list_to_dict(lang='en')}))
```

Code after:
            'series': 'Star Trek: The Original Series',
            'series_id': 'star-trek-the-original-series',
            'thumbnail': r're:https?://.+\.(?:jpg|png)',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        page_props = self._search_nextjs_data(webpage, video_id)['props']['pageProps']
        video_data = page_props['video']['data']
        if youtube_id := video_data.get('youtube_video_id'):
            return self.url_result(youtube_id, YoutubeIE)

        series_id = traverse_obj(video_data, (
            'series_and_movies', ..., 'series_or_movie', 'slug', {str}, any))

        return {
            'id': video_id,
            'series': traverse_obj(page_props, (
                'queried', 'header', 'tab3', 'slices', ..., 'items',
                lambda _, v: v['link']['slug'] == series_id, 'link_copy', {str}, any)),
            'series_id': series_id,
            **traverse_obj(video_data, {
                'title': ('title', ..., 'text', {clean_html}, any),
                'alt_title': ('subhead', ..., 'text', {clean_html}, any),
                'categories': ('category', 'data', 'category_name', {str.upper}, filter, all),
                'description': ('slices', ..., 'primary', 'content', ..., 'text', {clean_html}, any),
                'release_timestamp': ('published', {parse_iso8601}),
                'subtitles': ({'url': 'legacy_subtitle_file'}, all, {subs_list_to_dict(lang='en')}),
                'thumbnail': ('poster_frame', 'url', {url_or_none}, {update_url(query=None)}),
                'url': ('legacy_video_url', {url_or_none}),
            }),
        }