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

Code before:
            '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):
This can be written like so:
```suggestion
            'genre': genre,
            **traverse_obj(json, {
                'title': ('title', {str}),
                'artist': ('artist', {str}),
                'composer': ('composer_name', {str}),
                'thumbnail': (('picture_url_xlarge', 'picture_url'), {url_or_none}),
            }, get_all=False),
```
import `traverse_obj` from `..utils.traversal` and `url_or_none` from `..utils`. Tests will need to be adjusted.

Code after:
                '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',
        }
    }, {
        'url': 'https://mx3.ch/t/1C6E',
        'md5': '1afcd578493ddb8e5008e94bb6d97e25',
        'info_dict': {
            'id': '1C6E',
            'ext': 'wav',
            'artist': 'Alien Bubblegum',
            'album_artist': 'Alien Bubblegum',
            'composer': 'Alien Bubblegum',