mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-23 11:31:29 +01:00
use built-in geo handler
This commit is contained in:
parent
ceac9f669d
commit
3da3733d06
|
@ -34,7 +34,6 @@ class NetEaseMusicBaseIE(InfoExtractor):
|
||||||
'sky', # SVIP tier; 沉浸环绕声 (Surround Audio); flac
|
'sky', # SVIP tier; 沉浸环绕声 (Surround Audio); flac
|
||||||
)
|
)
|
||||||
_API_BASE = 'http://music.163.com/api/'
|
_API_BASE = 'http://music.163.com/api/'
|
||||||
_GEO_BYPASS = False
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _kilo_or_none(value):
|
def _kilo_or_none(value):
|
||||||
|
@ -68,6 +67,8 @@ def _download_eapi_json(self, path, video_id, query_body, headers={}, **kwargs):
|
||||||
'MUSIC_U': ('MUSIC_U', {lambda i: i.value}),
|
'MUSIC_U': ('MUSIC_U', {lambda i: i.value}),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
if self._x_forwarded_for_ip:
|
||||||
|
headers.setdefault('X-Real-IP', self._x_forwarded_for_ip)
|
||||||
return self._download_json(
|
return self._download_json(
|
||||||
urljoin('https://interface3.music.163.com/', f'/eapi{path}'), video_id,
|
urljoin('https://interface3.music.163.com/', f'/eapi{path}'), video_id,
|
||||||
data=self._create_eapi_cipher(f'/api{path}', query_body, cookies), headers={
|
data=self._create_eapi_cipher(f'/api{path}', query_body, cookies), headers={
|
||||||
|
@ -76,23 +77,20 @@ def _download_eapi_json(self, path, video_id, query_body, headers={}, **kwargs):
|
||||||
**headers,
|
**headers,
|
||||||
}, **kwargs)
|
}, **kwargs)
|
||||||
|
|
||||||
def _call_player_api(self, song_id, level, headers={}):
|
def _call_player_api(self, song_id, level):
|
||||||
return self._download_eapi_json(
|
return self._download_eapi_json(
|
||||||
'/song/enhance/player/url/v1', song_id,
|
'/song/enhance/player/url/v1', song_id,
|
||||||
{'ids': f'[{song_id}]', 'level': level, 'encodeType': 'flac'},
|
{'ids': f'[{song_id}]', 'level': level, 'encodeType': 'flac'},
|
||||||
headers=headers, note=f'Downloading song URL info: level {level}')
|
note=f'Downloading song URL info: level {level}')
|
||||||
|
|
||||||
def _extract_formats(self, info, try_geo_bypass=False):
|
def _extract_formats(self, info):
|
||||||
formats = []
|
formats = []
|
||||||
song_id = info['id']
|
song_id = info['id']
|
||||||
headers = {'X-Real-IP': '118.88.88.88'} if try_geo_bypass else {}
|
|
||||||
for level in self._LEVELS:
|
for level in self._LEVELS:
|
||||||
song = traverse_obj(
|
song = traverse_obj(
|
||||||
self._call_player_api(song_id, level, headers=headers), ('data', lambda _, v: url_or_none(v['url']), any))
|
self._call_player_api(song_id, level), ('data', lambda _, v: url_or_none(v['url']), any))
|
||||||
if not song: # Media is not available due to removal or geo-restriction
|
if not song:
|
||||||
if not try_geo_bypass:
|
break # Media is not available due to removal or geo-restriction
|
||||||
return self._extract_formats(info, try_geo_bypass=True)
|
|
||||||
break
|
|
||||||
actual_level = song.get('level')
|
actual_level = song.get('level')
|
||||||
if actual_level and actual_level != level:
|
if actual_level and actual_level != level:
|
||||||
if level in ('lossless', 'jymaster'):
|
if level in ('lossless', 'jymaster'):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user