use "api.imjad.cn" to fixed some song get 404 problem

This commit is contained in:
bigfuji 2017-05-05 23:51:32 +08:00 committed by kaka
parent f65fe485cd
commit 0e8931947a

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
from urllib.error import HTTPError
__all__ = ['netease_download'] __all__ = ['netease_download']
@ -108,6 +108,7 @@ def netease_video_download(vinfo, output_dir='.', info_only=False):
def netease_song_download(song, output_dir='.', info_only=False, playlist_prefix=""): def netease_song_download(song, output_dir='.', info_only=False, playlist_prefix=""):
title = "%s%s. %s" % (playlist_prefix, song['position'], song['name']) title = "%s%s. %s" % (playlist_prefix, song['position'], song['name'])
songNet = 'p' + song['mp3Url'].split('/')[2][1:] songNet = 'p' + song['mp3Url'].split('/')[2][1:]
url_backup = loads(get_content(url="https://api.imjad.cn/cloudmusic/?type=song&id=%s&br=320000" % song['id']))
if 'hMusic' in song and song['hMusic'] != None: if 'hMusic' in song and song['hMusic'] != None:
url_best = make_url(songNet, song['hMusic']['dfsId']) url_best = make_url(songNet, song['hMusic']['dfsId'])
@ -115,9 +116,14 @@ def netease_song_download(song, output_dir='.', info_only=False, playlist_prefix
url_best = song['mp3Url'] url_best = song['mp3Url']
elif 'bMusic' in song: elif 'bMusic' in song:
url_best = make_url(songNet, song['bMusic']['dfsId']) url_best = make_url(songNet, song['bMusic']['dfsId'])
url_backup = get_content(
url="https://api.imjad.cn/cloudmusic/?type=song&id=%s&br=320000" % song['bMusic']['dfsId'])
try:
netease_download_common(title, url_best, netease_download_common(title, url_best,
output_dir=output_dir, info_only=info_only) output_dir=output_dir, info_only=info_only)
except HTTPError:
netease_download_common(title, url_backup['data'][0]['url'],
output_dir=output_dir, info_only=info_only)
def netease_download_common(title, url_best, output_dir, info_only): def netease_download_common(title, url_best, output_dir, info_only):
songtype, ext, size = url_info(url_best) songtype, ext, size = url_info(url_best)