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

Code before:
        formats, subtitles = [], {}
        for key, value in video_source.items():
            if key == 'mp4':
                for video_mp4 in value:
                    fmts = [{
                        'url': video_mp4.get('url'),
                        'ext': 'mp4'
                    }]
                    formats.extend(fmts)

            elif key == 'hls':
                for video_hls in value:
                    fmts, subs = self._extract_m3u8_formats_and_subtitles(video_hls.get('url'), video_id)
                    formats.extend(fmts)
                    self._merge_subtitles(subs, target=subtitles)
        return formats, subtitles

    def _get_more_subtitle(self, caption_json):
        subs = {}
        for caption in caption_json:
            short_lang_code = caption.get('language')
            if subs.get(short_lang_code) is None:
                subs[short_lang_code] = []

            if short_lang_code:
                subs[short_lang_code] = [{'url': caption.get('vttUrl'), 'name': caption.get('name')}]

        return subs

    def _real_extract(self, url):
        display_id, season_number, episode_number = self._match_valid_url(url).group('id', 'season_num', 'episode_num')
        webpage = self._download_webpage(url, display_id)

        external_id = self._search_regex(r'externalid\s*=\s*"([^"]+)', webpage, 'externalid')
        json_data = self._download_json(
            f'https://play.vidyard.com/player/{external_id}.json', display_id)['payload']['chapters'][0]

        formats, subtitles = self._get_formats_and_subtitle(json_data['sources'], display_id)
        self._merge_subtitles(self._get_more_subtitle(json_data.get('captions')), target=subtitles)

        return {
            'id': str(json_data['videoId']),
            'title': json_data.get('name') or self._html_search_meta(['og:title', 'twitter:title'], webpage),
            'description': (json_data.get('description')
                            or self._html_search_meta(['og:description', 'twitter:description'])),
            'duration': int_or_none(json_data.get('seconds')),
            'formats': formats,
            'subtitles': subtitles,
            'season_number': int_or_none(season_number),
            'episode_number': int_or_none(episode_number),
            'thumbnails': [{'url': thumbnail_url} for thumbnail_url in traverse_obj(json_data, ('thumbnailUrls', ...))]

Review comment (suggestion):
```suggestion
            subs.setdefault(caption.get('language') or 'und', []).append({
                'url': caption.get('vttUrl'),
                'name': caption.get('name')
            })
```

Code after:
        formats, subtitles = [], {}
        for key, value in video_source.items():
            if key == 'hls':
                for video_hls in value:
                    fmts, subs = self._extract_m3u8_formats_and_subtitles(video_hls.get('url'), video_id)
                    formats.extend(fmts)
                    self._merge_subtitles(subs, target=subtitles)
            else:
                formats.extend({
                    'url': video_mp4.get('url'),
                    'ext': 'mp4'
                } for video_mp4 in value)

        return formats, subtitles

    def _get_direct_subtitle(self, caption_json):
        subs = {}
        for caption in caption_json:
            subs.setdefault(caption.get('language') or 'und', []).append({
                'url': caption.get('vttUrl'),
                'name': caption.get('name')
            })

        return subs

    def _real_extract(self, url):
        display_id, season_number, episode_number = self._match_valid_url(url).group('id', 'season_num', 'episode_num')
        webpage = self._download_webpage(url, display_id)

        external_id = self._search_regex(r'externalid\s*=\s*"([^"]+)', webpage, 'externalid')
        json_data = self._download_json(
            f'https://play.vidyard.com/player/{external_id}.json', display_id)['payload']['chapters'][0]

        formats, subtitles = self._get_formats_and_subtitle(json_data['sources'], display_id)
        self._merge_subtitles(self._get_direct_subtitle(json_data.get('captions')), target=subtitles)

        return {
            'id': str(json_data['videoId']),
            'title': json_data.get('name') or self._html_search_meta(['og:title', 'twitter:title'], webpage),
            'description': (json_data.get('description')
                            or self._html_search_meta(['og:description', 'twitter:description'])),
            'duration': int_or_none(json_data.get('seconds')),
            'formats': formats,
            'subtitles': subtitles,
            'season_number': int_or_none(season_number),
            'episode_number': int_or_none(episode_number),
            'thumbnails': [{'url': thumbnail_url}
                           for thumbnail_url in traverse_obj(json_data, ('thumbnailUrls', ...))]
        }