mirror of
https://github.com/MeoProject/lx-music-api-server.git
synced 2025-07-06 22:42:14 +08:00
chore: 完善返回数据
This commit is contained in:
@ -11,20 +11,25 @@ from common import Httpx
|
||||
from common.exceptions import FailedException
|
||||
|
||||
tools = {
|
||||
'qualityMap': {
|
||||
'128k': '128kmp3',
|
||||
'320k': '320kmp3',
|
||||
'flac': '2000kflac',
|
||||
},
|
||||
'extMap': {
|
||||
'128k': 'mp3',
|
||||
'320k': 'mp3',
|
||||
'flac': 'flac',
|
||||
}
|
||||
'qualityMap': {
|
||||
'128k': '128kmp3',
|
||||
'320k': '320kmp3',
|
||||
'flac': '2000kflac',
|
||||
},
|
||||
'qualityMapReverse': {
|
||||
'128': '128k',
|
||||
'320': '320k',
|
||||
'2000': 'flac',
|
||||
},
|
||||
'extMap': {
|
||||
'128k': 'mp3',
|
||||
'320k': 'mp3',
|
||||
'flac': 'flac',
|
||||
}
|
||||
}
|
||||
|
||||
async def url(songId, quality):
|
||||
target_url = f'''https://bd-api.kuwo.cn/api/service/music/downloadInfo/{songId}?isMv=0&format={tools['extMap'][quality]}&br={tools['qualityMap'][quality]}&level='''
|
||||
target_url = f'''https://bd-api.kuwo.cn/api/service/music/downloadInfo/{songId}?isMv=0&format={tools['extMap'][quality]}&br={tools['qualityMap'][quality]}'''
|
||||
req = Httpx.request(target_url, {
|
||||
'method': 'GET',
|
||||
'headers': {
|
||||
@ -39,8 +44,14 @@ async def url(songId, quality):
|
||||
})
|
||||
try:
|
||||
body = req.json()
|
||||
if (body['code'] != 200) or (body['data']['audioInfo']['bitrate'] == 1):
|
||||
data = body['data']
|
||||
|
||||
if (body['code'] != 200) or (data['audioInfo']['bitrate'] == 1):
|
||||
raise FailedException('failed')
|
||||
return body['data']['url'].split('?')[0]
|
||||
|
||||
return {
|
||||
'url': data['url'].split('?')[0],
|
||||
'quality': tools['qualityMapReverse'][data['audioInfo']['bitrate']]
|
||||
}
|
||||
except:
|
||||
raise FailedException('failed')
|
Reference in New Issue
Block a user