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

Code before:
            urlh = self._request_webpage(HEADRequest(fmt['url']), track_id, note='Fetching media headers', fatal=False)
            if urlh:
                fmt['ext'] = urlhandle_detect_ext(urlh)
                formats.append(fmt)

        add_format({
            'url': 'https://mx3.ch/' + json['url'],
            'format_id': 'default',
            'quality': 1,
        })

        if 'hd_url' in json:
            add_format({
                'url': 'https://mx3.ch/' + json['hd_url'],
                'format_id': 'hd',
                'quality': 10,
            })

        # the "download" feature is not available everywhere
        if f'/tracks/{track_id}/download' in webpage:
            add_format({
                'url': f'https://mx3.ch/tracks/{track_id}/download',
                'format_id': 'download',
                'quality': 11,
                'format_note': 'usually uncompressed WAV',
            })

        return {
            'id': track_id,
            'formats': formats,
            'title': title,
            'artist': artist,
            'genre': genre,
            'thumbnail': json.get('picture_url_xlarge') or json.get('picture_url'),
        }


Review comment (suggestion):
I wonder if given that we need to make a HEAD request anyway, we should just attempt to add all formats:
```suggestion
        add_format({
            'url': f'https://mx3.ch/tracks/{track_id}/player_asset',
            'format_id': 'default',
            'quality': 1,
        })

        add_format({
            'url': f'https://mx3.ch/tracks/{track_id}/player_asset?quality=hd',
            'format_id': 'hd',
            'quality': 10,
        })

        add_format({
            'url': f'https://mx3.ch/tracks/{track_id}/download',
            'format_id': 'download',
            'quality': 11,
        })

        add_format({
            'url': f'https://mx3.ch/tracks/{track_id}/player_asset?quality=',
            'format_id': 'download_alternative,
            'quality': 11,
        })
```

Code after:
            'formats': self._extract_formats(track_id),
            'genre': self._html_search_regex(
                r'<div\b[^>]+class="single-band-genre"[^>]*>([^<]+)</div>', webpage, 'genre', default=None),
            'release_year': int_or_none(get_info_field('Year of creation')),
            'description': get_info_field('Description'),
            'tags': try_call(lambda: get_info_field('Tag').split(', '), list),
            **traverse_obj(data, {
                'title': ('title', {str}),
                'artist': (('performer_name', 'artist'), {str}),
                'album_artist': ('artist', {str}),
                'composer': ('composer_name', {str}),
                'thumbnail': (('picture_url_xlarge', 'picture_url'), {url_or_none}),
            }, get_all=False),
        }


class Mx3IE(Mx3BaseIE):
    _DOMAIN = 'mx3.ch'
    _VALID_URL = Mx3BaseIE._VALID_URL_TMPL % re.escape(_DOMAIN)
    _TESTS = [{
        'url': 'https://mx3.ch/t/1Cru',
        'md5': '7ba09e9826b4447d4e1ce9d69e0e295f',
        'info_dict': {
            'id': '1Cru',
            'ext': 'wav',
            'artist': 'Godina',
            'album_artist': 'Tortue Tortue',
            'composer': 'Olivier Godinat',
            'genre': 'Rock',
            'thumbnail': 'https://mx3.ch/pictures/mx3/file/0101/4643/square_xlarge/1-s-envoler-1.jpg?1630272813',
            'title': "S'envoler",
            'release_year': 2021,
            'tags': [],
        }
    }, {
        'url': 'https://mx3.ch/t/1LIY',
        'md5': '48293cb908342547827f963a5a2e9118',
        'info_dict': {
            'id': '1LIY',
            'ext': 'mov',
            'artist': 'Tania Kimfumu',
            'album_artist': 'The Broots',
            'composer': 'Emmanuel Diserens',
            'genre': 'Electro',
            'thumbnail': 'https://mx3.ch/pictures/mx3/file/0110/0003/video_xlarge/frame_0000.png?1686963670',
            'title': 'The Broots-Larytta remix "Begging For Help"',
            'release_year': 2023,
            'tags': ['the broots', 'cassata records', 'larytta'],
            'description': '"Begging for Help" Larytta Remix Official Video\nRealized By Kali Donkilie in 2023',
        }
    }, {