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

Code before:

        formats = []
        for published_url in video_data['published_urls']:
            video_url = published_url.get('embed_url')
            if not video_url:
                continue
            media_format = published_url.get('format')
            ext = determine_ext(video_url)

            if ext == 'smil' or media_format == 'smil':
                formats.extend(self._extract_smil_formats(video_url, video_id))
                continue

            tbr = int_or_none(published_url.get('kbps'))
            a_format = {
                'url': video_url,
                'format_id': join_nonempty('http', published_url.get('cdn_name')).lower(),
                'tbr': tbr or None,
            }

            vtt_subs, hls_subs = {}, {}
            if media_format == 'vtt':
                no_fmt, vtt_subs = self._extract_m3u8_formats_and_subtitles(
                    video_url, video_id, ext='vtt', entry_protocol='m3u8_native',
                    m3u8_id='vtt', fatal=False)
                continue
            elif media_format == 'm3u8' and tbr is not None:
                a_format.update({
                    'format_id': join_nonempty('hls', tbr),
                    'ext': 'mp4',
                })
            elif media_format == 'm3u8-variant' or ext == 'm3u8':
                # For some videos the initial m3u8 URL returns JSON instead
                try:
                    manifest_json = self._download_json(
                        video_url, video_id, note='Downloading manifest JSON')
                except ExtractorError:
                    pass
                else:
                    video_url = manifest_json.get('master_m3u8')
                    if not video_url:
                        continue
                hls_fmts, hls_subs = self._extract_m3u8_formats_and_subtitles(
                    video_url, video_id, ext='mp4', entry_protocol='m3u8_native',
                    m3u8_id='hls', fatal=False)
                formats.extend(hls_fmts)
                continue
            elif ext == 'mp3' or media_format == 'mp3':
                a_format['vcodec'] = 'none'
            else:
                a_format.update({

Review comment (refactor):
```suggestion
            if media_format == 'vtt':  # There are no formats
                _, vtt_subs = self._extract_m3u8_formats_and_subtitles(
                    video_url, video_id, m3u8_id='vtt', fatal=False)
                continue
```

Code after:

            if ext == 'smil' or media_format == 'smil':
                formats.extend(self._extract_smil_formats(video_url, video_id))
                continue

            tbr = int_or_none(published_url.get('kbps'))
            a_format = {
                'url': video_url,
                'format_id': join_nonempty('http', published_url.get('cdn_name')).lower(),
                'tbr': tbr or None,
            }

            vtt_subs, hls_subs = {}, {}
            if media_format == 'vtt':
                _, vtt_subs = self._extract_m3u8_formats_and_subtitles(
                    video_url, video_id, m3u8_id='vtt', fatal=False)
                continue
            elif media_format == 'm3u8' and tbr is not None:
                a_format.update({
                    'format_id': join_nonempty('hls', tbr),
                    'ext': 'mp4',
                })
            elif media_format == 'm3u8-variant' or ext == 'm3u8':
                # For some videos the initial m3u8 URL returns JSON instead
                manifest_json = self._download_json(
                    video_url, video_id, note='Downloading manifest JSON', errnote=False)
                if manifest_json:
                    video_url = manifest_json.get('master_m3u8')
                    if not video_url:
                        continue
                hls_fmts, hls_subs = self._extract_m3u8_formats_and_subtitles(
                    video_url, video_id, ext='mp4', m3u8_id='hls', fatal=False)
                formats.extend(hls_fmts)
                continue
            elif ext == 'mp3' or media_format == 'mp3':
                a_format['vcodec'] = 'none'
            else:
                a_format.update({
                    'width': int_or_none(published_url.get('width')),
                    'height': int_or_none(published_url.get('height')),
                })
            formats.append(a_format)

        self._sort_formats(formats)

        subtitles = {}
        for caption in video_data.get('captions', []):
            a_caption = {
                'url': caption['url'],
                'ext': 'tt' if caption.get('format') == 'SMPTE-TT' else None
            }