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

Code before:
            'title': 'Season 5 Episode 3:  Woes',
            'description': 'md5:90ca3cc41316a965fd1cd3d5b3458784',
            'duration': 3519,
            'thumbnail': 'https://cdn.thechosen.media/videos/cmkoltsl8000dfd5z3luid3mg/thumbnail.jpg',
        },
        'params': {'skip_download': 'm3u8'},
    }]
    _API_TMPL = 'https://api.watch.thechosen.tv/v1/videos/{}'

    def _real_extract(self, url):
        video_id = self._match_id(url)
        metadata = self._download_json(self._API_TMPL.format(video_id), video_id)

        formats, subtitles = [], {}
        video_data = traverse_obj(metadata, ('details', 'video'))
        for item in video_data:
            vurl = item.get('url')
            if not vurl:
                continue
            ext = determine_ext(vurl)
            if ext == 'm3u8':
                formats, subtitles = self._extract_m3u8_formats_and_subtitles(vurl, video_id)
                formats.extend(formats)
            elif ext == 'mpd':
                formats, subtitles = self._extract_mpd_formats_and_subtitles(vurl, video_id)
                subtitles.utend(formats)
                subtitles.update(subtitles)
            else:
                continue

        thumbnails = []
        if thumb_data := traverse_obj(metadata, ('thumbs'), ('thumbnails'), default=None):
            for _, thumb_url in thumb_data.items():
                if thumb_url is None:
                    continue
                thumbnails.append({'url': thumb_url})

        return {
            'id': video_id,
            **traverse_obj(metadata, ({
                'title': ('title'),
                'description': ('description'),
                'duration': ('duration'),
            })),
            'thumbnails': thumbnails,
            'formats': formats,
            'subtitles': self._merge_subtitles(subtitles),
        }


class TheChosenGroupIE(FrontroGroupBaseIE):

Review comment (bug):
some problems here:
- you're trying to extend `formats` and update `subtitles`, but you are overwriting the variable every iteration
- `subtitles.utend(formats)`
- you're discarding the m3u8 subs. is that intentional?
- if we're looping like this and have multiple opportunities to extract formats, the `_extract_*_formats` calls should be non-fatal so that we don't fail early

use temp vars like `fmts` and `subs` and then do `formats.extend(fmts)` and `self._merge_subtitles(subs, target=subtitles)`

we should also warn if the `ext` is unexpected/unsupported
```suggestion
            if ext == 'm3u8':
                fmts, subs = self._extract_m3u8_formats_and_subtitles(vurl, video_id, 'mp4', fatal=False)
            elif ext == 'mpd':
                fmts, subs = self._extract_mpd_formats_and_subtitles(vurl, video_id, fatal=False)
            else:
                self.report_warning(f'Skipping unsupported format extension "{ext}"', video_id=video_id)
                continue
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)
```

Code after:
        'url': 'https://watch.thechosen.tv/video/184683621750',
        'info_dict': {
            'id': '184683621750',
            'ext': 'mp4',
            'title': 'Season 5 Episode 3:  Woes',
            'description': 'md5:90ca3cc41316a965fd1cd3d5b3458784',
            'duration': 3519,
            'thumbnail': 'https://cdn.thechosen.media/videos/cmkoltsl8000dfd5z3luid3mg/thumbnail.jpg',
        },
        'params': {'skip_download': 'm3u8'},
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        metadata = self._download_json(f'https://api.watch.thechosen.tv/v1/videos/{video_id}', video_id)

        formats, subtitles = [], {}
        for fmt_url in traverse_obj(metadata, ('details', 'video', ..., 'url', {url_or_none})):
            ext = determine_ext(fmt_url)
            if ext == 'm3u8':
                fmts, subs = self._extract_m3u8_formats_and_subtitles(fmt_url, video_id, 'mp4', fatal=False)
            elif ext == 'mpd':
                fmts, subs = self._extract_mpd_formats_and_subtitles(fmt_url, video_id, fatal=False)
            else:
                self.report_warning(f'Skipping unsupported format extension "{ext}"', video_id=video_id)
                continue
            formats.extend(fmts)
            self._merge_subtitles(subs, target=subtitles)

        thumbnails = []
        for thumb_id, thumb_url in traverse_obj(metadata, (
            ('thumbs', 'thumbnails'), {dict.items}, lambda _, v: url_or_none(v[1]),
        )):
            thumbnails.append({
                'id': thumb_id,
                'url': thumb_url,
            })

        return {
            'id': video_id,
            **traverse_obj(metadata, ({
                'title': ('title', {str}),
                'description': ('description', {str}),
                'duration': ('duration', {int_or_none}),
            })),
            'thumbnails': thumbnails,
            'formats': formats,
            'subtitles': subtitles,
        }