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

Code before:
        'info_dict': {
            'id': '7x0e6l',
            'ext': 'mp4',
            'title': '7x0e6l',
        },
    }]
    _WEBPAGE_TESTS = [{
        'url': 'https://www.petfinder.com/dog/gus-57378930/tn/ooltewah/furever-furkids-rescue-tn592/',
        'info_dict': {
            'id': 'w8p5b0',
            'ext': 'mp4',
            'title': 'w8p5b0',
            'thumbnail': r're:https://\w+\.cloudfront\.net/',
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)

        embed_script = self._download_webpage(
            f'https://vid.ly/{video_id}/embed', video_id, headers={'Referer': 'https://vid.ly/'})
        player = self._search_json(r'initCallback\(', embed_script, 'player', video_id)

        if player['player'].startswith('jwplayer'):
            return self._parse_jwplayer_data(player['config'], video_id)
        elif player['player'] == 'vidlyplayer':
            formats = []
            ext = mimetype2ext(traverse_obj(player, ('config', 'type')))
            if traverse_obj(player, ('config', 'source', {url_or_none})):
                formats.append({
                    'url': player['config']['source'],
                    'format_id': 'http-sd',
                    'ext': ext,
                })
            if traverse_obj(player, ('config', 'source_hd', {url_or_none})):
                formats.append({
                    'url': player['config']['source_hd'],
                    'format_id': 'http-hd',
                    'ext': ext,
                })
            # Has higher quality formats
            formats.extend(self._extract_m3u8_formats(
                f'https://d3fenhwk93s16g.cloudfront.net/{video_id}/hls.m3u8', video_id,
                fatal=False, note='Trying to guess m3u8 URL') or [])
            return {
                'id': video_id,
                'title': video_id,
                'formats': formats,
            }
        else:
            raise ExtractorError('Unknown player type')

Review comment (refactor):
we could do this and then unindent everything below it (and remove the duplicate raise ofc)
```suggestion
        player_type = player.get('player') or ''
        if player_type.startswith('jwplayer'):
            return self._parse_jwplayer_data(player['config'], video_id)
        elif player_type != 'vidlyplayer':
            raise ExtractorError(f'Unknown player type {player_type!r}')
```

Code after:
        'info_dict': {
            'id': '7x0e6l',
            'ext': 'mp4',
            'title': '7x0e6l',
        },
    }]
    _WEBPAGE_TESTS = [{
        'url': 'https://www.petfinder.com/dog/gus-57378930/tn/ooltewah/furever-furkids-rescue-tn592/',
        'info_dict': {
            'id': 'w8p5b0',
            'ext': 'mp4',
            'title': 'w8p5b0',
            'thumbnail': r're:https://\w+\.cloudfront\.net/',
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)

        embed_script = self._download_webpage(
            f'https://vid.ly/{video_id}/embed', video_id, headers={'Referer': 'https://vid.ly/'})
        player = self._search_json(r'initCallback\(', embed_script, 'player', video_id)

        player_type = player.get('player') or ''
        if player_type.startswith('jwplayer'):
            return self._parse_jwplayer_data(player['config'], video_id)
        elif not player_type.startswith('vidly'):
            raise ExtractorError(f'Unknown player type {player_type!r}')

        formats = []
        ext = mimetype2ext(traverse_obj(player, ('config', 'type')))
        for source, fid in [('source', 'sd'), ('source_hd', 'hd')]:
            if traverse_obj(player, ('config', source, {url_or_none})):
                formats.append({
                    'url': player['config'][source],
                    'format_id': f'http-{fid}',
                    'ext': ext,
                })
        # Has higher quality formats
        formats.extend(self._extract_m3u8_formats(
            f'https://d3fenhwk93s16g.cloudfront.net/{video_id}/hls.m3u8', video_id,
            fatal=False, note='Requesting higher quality m3u8 formats',
            errnote='No higher quality m3u8 formats found') or [])

        return {
            'id': video_id,
            'title': video_id,
            'formats': formats,
        }