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

Code before:
            'age_limit': 14,
            'duration': 2640.0,
            'tags': ['True Crime', 'Murder'],
        },
        'params': {'skip_download': 'm3u8'},
    }, {
        'url': 'https://www.magellantv.com/watch/celebration-nation?type=s',
        'info_dict': {
            'id': 'celebration-nation',
            'ext': 'mp4',
            'tags': ['Art & Culture', 'Human Interest', 'Anthropology', 'China', 'History'],
            'duration': 2640.0,
            'title': 'Ancestors',
        },
        'params': {'skip_download': 'm3u8'},
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        data = traverse_obj(self._search_nextjs_data(webpage, video_id), (
            'props', 'pageProps', 'reactContext',
            (('video', 'detail'), ('series', 'currentEpisode')), {dict}), get_all=False)
        formats = []
        subtitles = {}
        for url in traverse_obj(data, ((('manifests', ..., 'hls'), 'jwp_video_url'), {url_or_none})):
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                url, video_id, 'mp4', m3u8_id='hls', fatal=False)
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)

        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(data, {
                'title': ('title', {str}),
                'description': ('metadata', 'description', {str}),
                'duration': ('duration', {parse_duration}),
                'age_limit': ('ratingCategory', {parse_age_limit}),
                'tags': ('tags', ..., {str}),
            }),
        }


Review comment (refactor):
Is this getting duplicate formats? 

I think `subs` only come from `v2` in the Ellipsis: hence it should be enough to use that if present and any other (probably, `v1` which I found to give the same as the `jwp_video_url`) if not.

Code after:
            'age_limit': 14,
            'duration': 2640.0,
            'tags': ['True Crime', 'Murder'],
        },
        'params': {'skip_download': 'm3u8'},
    }, {
        'url': 'https://www.magellantv.com/watch/celebration-nation?type=s',
        'info_dict': {
            'id': 'celebration-nation',
            'ext': 'mp4',
            'tags': ['Art & Culture', 'Human Interest', 'Anthropology', 'China', 'History'],
            'duration': 2640.0,
            'title': 'Ancestors',
        },
        'params': {'skip_download': 'm3u8'},
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        context = self._search_nextjs_data(webpage, video_id)['props']['pageProps']['reactContext']
        data = traverse_obj(context, ((('video', 'detail'), ('series', 'currentEpisode')), {dict}, any))

        formats, subtitles = [], {}
        for m3u8_url in set(traverse_obj(data, ((('manifests', ..., 'hls'), 'jwp_video_url'), {url_or_none}))):
            fmts, subs = self._extract_m3u8_formats_and_subtitles(
                m3u8_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)
        if not formats and (error := traverse_obj(context, ('errorDetailPage', 'errorMessage', {str}))):
            if 'available in your country' in error:
                self.raise_geo_restricted(msg=error)
            self.raise_no_formats(f'{self.IE_NAME} said: {error}', expected=True)

        return {
            'id': video_id,
            'formats': formats,
            'subtitles': subtitles,
            **traverse_obj(data, {
                'title': ('title', {str}),
                'description': ('metadata', 'description', {str}),
                'duration': ('duration', {parse_duration}),
                'age_limit': ('ratingCategory', {parse_age_limit}),
                'tags': ('tags', ..., {str}),
            }),
        }