mirror of
https://github.com/MeoProject/lx-music-api-server.git
synced 2025-07-07 06:52:11 +08:00
feat: 将所有api请求更换为异步,提高速度
This commit is contained in:
@ -49,7 +49,8 @@ async def getMusicInfo(hash_, use_cache = True):
|
|||||||
'cache-ignore': [tn]
|
'cache-ignore': [tn]
|
||||||
}
|
}
|
||||||
options['body'] = json.dumps(options['data']).replace(', ', ',').replace(': ', ':')
|
options['body'] = json.dumps(options['data']).replace(', ', ',').replace(': ', ':')
|
||||||
body = Httpx.request(url, dict(options)).json()
|
body = await Httpx.AsyncRequest(url, dict(options))
|
||||||
|
body = body.json()
|
||||||
return body['data'][0][0] if (body['data'] and body['data'][0]) else {}
|
return body['data'][0][0] if (body['data'] and body['data'][0]) else {}
|
||||||
|
|
||||||
async def getMusicSingerInfo(hash_, use_cache = True):
|
async def getMusicSingerInfo(hash_, use_cache = True):
|
||||||
@ -94,4 +95,12 @@ async def getMusicSingerInfo(hash_, use_cache = True):
|
|||||||
'avatar': a['sizable_avatar'].format(size = 1080),
|
'avatar': a['sizable_avatar'].format(size = 1080),
|
||||||
'sizable_avatar': a['sizable_avatar'],
|
'sizable_avatar': a['sizable_avatar'],
|
||||||
})
|
})
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
async def getMusicMVHash(hash_, use_cache = True):
|
||||||
|
req = await Httpx.AsyncRequest('http://mobilecdnbj.kugou.com/api/v3/song/info?hash=' + hash_, {
|
||||||
|
'method': 'GET',
|
||||||
|
'cache': 86400 * 30 if use_cache else 'no-cache',
|
||||||
|
})
|
||||||
|
body = req.json()
|
||||||
|
return body['data']['mvhash'] if (body['data']) else ''
|
@ -58,7 +58,7 @@ def sign(params, body = "", signkey = tools["signkey"]):
|
|||||||
async def signRequest(url, params, options, signkey = tools["signkey"]):
|
async def signRequest(url, params, options, signkey = tools["signkey"]):
|
||||||
params['signature'] = sign(params, options.get("body") if options.get("body") else (options.get("data") if options.get("data") else ""), signkey)
|
params['signature'] = sign(params, options.get("body") if options.get("body") else (options.get("data") if options.get("data") else ""), signkey)
|
||||||
url = url + "?" + buildRequestParams(params)
|
url = url + "?" + buildRequestParams(params)
|
||||||
return Httpx.request(url, options)
|
return await Httpx.AsyncRequest(url, options)
|
||||||
|
|
||||||
def getKey(hash_):
|
def getKey(hash_):
|
||||||
return utils.createMD5(hash_.lower() + tools.pidversec + tools.appid + tools.mid + tools.userid)
|
return utils.createMD5(hash_.lower() + tools.pidversec + tools.appid + tools.mid + tools.userid)
|
||||||
|
@ -30,7 +30,7 @@ tools = {
|
|||||||
|
|
||||||
async def url(songId, quality):
|
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]}'''
|
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, {
|
req = await Httpx.AsyncRequest(target_url, {
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
'headers': {
|
'headers': {
|
||||||
'User-Agent': 'okhttp/3.10.0',
|
'User-Agent': 'okhttp/3.10.0',
|
||||||
|
@ -32,7 +32,7 @@ tools = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async def url(songId, quality):
|
async def url(songId, quality):
|
||||||
req = Httpx.request(tools['url'].replace('__quality__', tools['qualityMap'][quality]).replace('__songId__', songId), {
|
req = await Httpx.AsyncRequest(tools['url'].replace('__quality__', tools['qualityMap'][quality]).replace('__songId__', songId), {
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
'headers': {
|
'headers': {
|
||||||
'User-Agent': tools['useragent'],
|
'User-Agent': tools['useragent'],
|
||||||
|
10
modules/tx/mv.py
Normal file
10
modules/tx/mv.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# ----------------------------------------
|
||||||
|
# - mode: python -
|
||||||
|
# - author: helloplhm-qwq -
|
||||||
|
# - name: mv.py -
|
||||||
|
# - project: lx-music-api-server -
|
||||||
|
# - license: MIT -
|
||||||
|
# ----------------------------------------
|
||||||
|
# This file is part of the "lx-music-api-server" project.
|
||||||
|
|
||||||
|
# 没做
|
@ -7,7 +7,6 @@
|
|||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# This file is part of the "lx-music-api-server" project.
|
||||||
|
|
||||||
from common.exceptions import FailedException
|
|
||||||
from common import Httpx
|
from common import Httpx
|
||||||
from common import utils
|
from common import utils
|
||||||
from common import config
|
from common import config
|
||||||
@ -62,7 +61,7 @@ async def signRequest(data, cache = False):
|
|||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
s = sign(data)
|
s = sign(data)
|
||||||
headers = {}
|
headers = {}
|
||||||
return Httpx.request('https://u.y.qq.com/cgi-bin/musics.fcg?format=json&sign=' + s, {
|
return await Httpx.AsyncRequest('https://u.y.qq.com/cgi-bin/musics.fcg?format=json&sign=' + s, {
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
'body': data,
|
'body': data,
|
||||||
'headers': headers,
|
'headers': headers,
|
||||||
|
@ -38,7 +38,7 @@ tools = {
|
|||||||
async def url(songId, quality):
|
async def url(songId, quality):
|
||||||
path = '/api/song/enhance/player/url/v1'
|
path = '/api/song/enhance/player/url/v1'
|
||||||
requestUrl = 'https://interface.music.163.com/eapi/song/enhance/player/url/v1'
|
requestUrl = 'https://interface.music.163.com/eapi/song/enhance/player/url/v1'
|
||||||
req = Httpx.request(requestUrl, {
|
req = await Httpx.AsyncRequest(requestUrl, {
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
'headers': {
|
'headers': {
|
||||||
'Cookie': tools['cookie'],
|
'Cookie': tools['cookie'],
|
||||||
@ -49,14 +49,13 @@ async def url(songId, quality):
|
|||||||
"encodeType": "flac",
|
"encodeType": "flac",
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
body = json.loads(req.text)
|
body = req.json()
|
||||||
if (not body.get("data") or (not body.get("data")) or (not body.get("data")[0].get("url"))):
|
if (not body.get("data") or (not body.get("data")) or (not body.get("data")[0].get("url"))):
|
||||||
raise FailedException("failed")
|
raise FailedException("failed")
|
||||||
|
|
||||||
data = body["data"][0]
|
data = body["data"][0]
|
||||||
if (config.read_config('module.wy.reject_unmatched_quality')):
|
if (data['level'] != tools['qualityMap'][quality]):
|
||||||
if (data['level'] != tools['qualityMap'][quality]):
|
raise FailedException("reject unmatched quality")
|
||||||
raise FailedException("reject unmatched quality")
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'url': data["url"].split("?")[0],
|
'url': data["url"].split("?")[0],
|
||||||
|
Reference in New Issue
Block a user