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

Code before:
            }),
        }
        return self._download_json(
            urljoin('https://interface3.music.163.com/', f'/eapi{path}'), video_id,
            data=self._create_eapi_cipher(f'/api{path}', query_body, cookies), headers={
                'Referer': 'https://music.163.com',
                'Cookie': '; '.join([f'{k}={v}' for k, v in cookies.items()]),
                **headers,
            }, **kwargs)

    def _call_player_api(self, song_id, level):
        return self._download_eapi_json(
            '/song/enhance/player/url/v1', song_id, {'ids': f'[{song_id}]', 'level': level, 'encodeType': 'flac'},
            note=f'Downloading song URL info: level {level}')

    def extract_formats(self, info):
        err = 0
        formats = []
        song_id = info['id']
        for song_level in self._LEVELS:
            for song in traverse_obj(self._call_player_api(song_id, song_level), ('data', lambda _, v: url_or_none(v['url']))):
                song_url = song['url']
                if self._is_valid_url(song_url, info['id'], 'song'):
                    formats.append({
                        'url': song_url,
                        'format_id': song_level,
                        **traverse_obj(song, {
                            'ext': ('type', {str}),
                            'abr': ('br', {self.kilo_or_none}),
                            'filesize': ('size', {int_or_none}),
                        }),
                    })
                elif err == 0:
                    err = traverse_obj(song, ('code', {int})) or 0

        if not formats:
            if err != 0 and (err < 200 or err >= 400):
                raise ExtractorError(f'No media links found (site code {err})', expected=True)
            else:
                self.raise_geo_restricted(
                    'No media links found: probably due to geo restriction.', countries=['CN'])
        return formats

    def query_api(self, endpoint, video_id, note):
        result = self._download_json(
            f'{self._API_BASE}{endpoint}', video_id, note, headers={'Referer': self._API_BASE})
        code = traverse_obj(result, ('code', {int}))
        message = traverse_obj(result, ('message', {str})) or ''
        if code == -462:
            self.raise_login_required(f'Login required to download: {message}')
        elif code != 200:

Review comment (suggestion):
should also add this so yt-dlp knows it's an audio-only format
```suggestion
                        'format_id': song_level,
                        'vcodec': 'none',
```

Code after:
            'versioncode': '140',
            'mobilename': 'undefined',
            'buildver': '1623435496',
            'resolution': '1920x1080',
            '__csrf': '',
            'os': 'pc',
            'channel': 'undefined',
            'requestId': f'{int(time.time() * 1000)}_{random.randint(0, 1000):04}',
            **traverse_obj(self._get_cookies(self._API_BASE), {
                'MUSIC_U': ('MUSIC_U', {lambda i: i.value}),
            }),
        }
        return self._download_json(
            urljoin('https://interface3.music.163.com/', f'/eapi{path}'), video_id,
            data=self._create_eapi_cipher(f'/api{path}', query_body, cookies), headers={
                'Referer': 'https://music.163.com',
                'Cookie': '; '.join([f'{k}={v}' for k, v in cookies.items()]),
                **headers,
            }, **kwargs)

    def _call_player_api(self, song_id, level):
        return self._download_eapi_json(
            '/song/enhance/player/url/v1', song_id,
            {'ids': f'[{song_id}]', 'level': level, 'encodeType': 'flac'},
            note=f'Downloading song URL info: level {level}')

    def _extract_formats(self, info):
        formats = []
        song_id = info['id']
        for level in self._LEVELS:
            song = traverse_obj(
                self._call_player_api(song_id, level), ('data', lambda _, v: url_or_none(v['url']), any))
            if not song:
                break  # Media is not available due to removal or geo-restriction
            actual_level = song.get('level')
            if actual_level and actual_level != level:
                if level in ('lossless', 'jymaster'):
                    break  # We've already extracted the highest level of the user's account tier
                continue
            formats.append({
                'url': song['url'],
                'format_id': level,
                'vcodec': 'none',
                **traverse_obj(song, {
                    'ext': ('type', {str}),
                    'abr': ('br', {self._kilo_or_none}),
                    'filesize': ('size', {int_or_none}),
                }),
            })
            if not actual_level:
                break  # Only 1 level is available if API does not return a value (netease:program)