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

Code before:
        '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 set(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 (bug):
Maybe add some error handling (eg, 2nd test is geo-blocked in UK), s/t like this:
```suggestion
        context = traverse_obj(self._search_nextjs_data(webpage, video_id), (
            'props', 'pageProps', 'reactContext'))
        data = traverse_obj(context, (
            (('video', 'detail'), ('series', 'currentEpisode')), {dict}, any))
        formats = []
        subtitles = {}
        for url in set(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)

        if not formats:
            error_msg = traverse_obj(context, ('errorDetailPage', 'errorMessage'))
            error_txt = error_msg or '**no reason given**'
            if "isn't available in your country" in error_msg:
                self.raise_geo_restricted(msg=error_txt)
            else:
                self.raise_no_formats(f'Extraction failed because: {error_txt}', expected=bool(error_msg))
```

Code after:
        '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}),
            }),
        }