feat: 支持接入第三方提供的vkey api

This commit is contained in:
ikun 2024-09-16 14:52:12 +08:00
parent 15bfed2625
commit c9d5df7fe8
No known key found for this signature in database
GPG Key ID: 24A57561C4002CB4
2 changed files with 28 additions and 1 deletions

View File

@ -123,6 +123,9 @@ module:
enable: false enable: false
interval: 86000 interval: 86000
cdnaddr: http://ws.stream.qqmusic.qq.com/ cdnaddr: http://ws.stream.qqmusic.qq.com/
vkey_api: # 第三方Vkey获取API
use_vkey_api: false
vkey_api_url: "xxx"
wy: # 网易云音乐相关配置 wy: # 网易云音乐相关配置
user: # 账号cookie数据可以通过浏览器获取需要vip账号来获取会员歌曲如果没有请留为空值 user: # 账号cookie数据可以通过浏览器获取需要vip账号来获取会员歌曲如果没有请留为空值

View File

@ -8,7 +8,7 @@
# 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.exceptions import FailedException
from common import config, utils, variable from common import config, utils, variable, Httpx
from .musicInfo import getMusicInfo from .musicInfo import getMusicInfo
from .utils import tools from .utils import tools
from .utils import signRequest from .utils import signRequest
@ -16,9 +16,33 @@ import random
createObject = utils.CreateObject createObject = utils.CreateObject
index_map = {
'dolby': 4,
'master': 3
}
async def vkeyUrl(q, b):
apiNode = config.read_config("module.tx.vkey_api.vkey_api_url")
filename = b['track_info']['file']['media_mid']
if (q in index_map.keys()):
filename = b['track_info']['vs'][index_map[q]]
if (not filename): raise FailedException('未找到该音质')
filename = f"{tools.fileInfo[q]['h']}{filename}{tools.fileInfo[q]['e']}"
url = apiNode + f"?filename={filename}&guid={config.read_config('module.tx.vkeyserver.guid')}&uin={config.read_config('module.tx.vkeyserver.uin')}"
req = await Httpx.AsyncRequest(url)
body = req.json()
purl = body['data'][0]['purl']
return {
'url': tools.cdnaddr + purl,
'quality': q
}
async def url(songId, quality): async def url(songId, quality):
infoBody = await getMusicInfo(songId) infoBody = await getMusicInfo(songId)
strMediaMid = infoBody['track_info']['file']['media_mid'] strMediaMid = infoBody['track_info']['file']['media_mid']
if (config.read_config("module.tx.vkey_api.use_vkey_api")):
return await vkeyUrl(quality, infoBody)
user_info = config.read_config('module.tx.user') if (not variable.use_cookie_pool) else random.choice(config.read_config('module.cookiepool.tx')) user_info = config.read_config('module.tx.user') if (not variable.use_cookie_pool) else random.choice(config.read_config('module.cookiepool.tx'))
requestBody = { requestBody = {
'req_0': { 'req_0': {