feat: 将所有api请求更换为异步,提高速度

This commit is contained in:
helloplhm-qwq
2023-12-17 13:50:22 +08:00
parent 484adde934
commit 57977c82d2
7 changed files with 29 additions and 12 deletions

View File

@ -49,7 +49,8 @@ async def getMusicInfo(hash_, use_cache = True):
'cache-ignore': [tn]
}
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 {}
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),
'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 ''

View File

@ -58,7 +58,7 @@ def sign(params, body = "", 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)
url = url + "?" + buildRequestParams(params)
return Httpx.request(url, options)
return await Httpx.AsyncRequest(url, options)
def getKey(hash_):
return utils.createMD5(hash_.lower() + tools.pidversec + tools.appid + tools.mid + tools.userid)