feat: 支持QQ音乐刷新登录

This commit is contained in:
helloplhm-qwq
2023-12-23 16:41:05 +08:00
parent d9a13c5fe4
commit e71edf9e78
6 changed files with 120 additions and 5 deletions

View File

@ -160,6 +160,11 @@ default = {
"_uin-desc": "key对应的QQ号"
},
"cdnaddr": "http://ws.stream.qqmusic.qq.com/",
'refresh_login': {
'desc': '刷新登录相关配置enable是否启动interval刷新间隔',
'enable': False,
'interval': 86000
}
},
"wy": {
"desc": "网易云音乐相关配置",

View File

@ -12,6 +12,7 @@ import binascii
import builtins
import base64
import zlib
import time
import re
import xmltodict
from urllib.parse import quote
@ -153,5 +154,10 @@ def timeLengthFormat(t):
second = t % 60
return f"{((('0' + str(hour)) if (len(str(hour)) == 1) else str(hour)) + ':') if (hour > 0) else ''}{minute:02}:{second:02}"
def timestamp_format(t):
if (not isinstance(t, int)):
t = int(t)
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(t))
addToGlobalNamespace('require', require)

View File

@ -12,6 +12,7 @@ from .musicInfo import getMusicInfo as _getInfo
from .utils import formatSinger
from .lyric import getLyric as _getLyric
from common import utils
from . import refresh_login
async def info(songid):

View File

@ -8,7 +8,7 @@
# This file is part of the "lx-music-api-server" project.
from common.exceptions import FailedException
from common import utils
from common import config, utils
from .musicInfo import getMusicInfo
from .utils import tools
from .utils import signRequest
@ -33,8 +33,8 @@ async def url(songId, quality):
},
},
'comm': {
"qq": tools.loginuin,
"authst": tools.key,
"qq": config.read_config('module.tx.user.uin'),
"authst": config.read_config('module.tx.user.qqmusic_key'),
"ct": "26",
"cv": "2010101",
"v": "2010101"

105
modules/tx/refresh_login.py Normal file
View File

@ -0,0 +1,105 @@
# ----------------------------------------
# - mode: python -
# - author: helloplhm-qwq -
# - name: refresh_login.py -
# - project: lx-music-api-server -
# - license: MIT -
# ----------------------------------------
# This file is part of the "lx-music-api-server" project.
from common import Httpx
from common import scheduler
from common import config
from common import log
from .utils import sign
import ujson as json
logger = log.log('qqmusic_refresh_login')
async def refresh():
if (not config.read_config('module.tx.user.qqmusic_key')):
return
if (not config.read_config('module.tx.refresh_login.enable')):
return
if (config.read_config('module.tx.user.qqmusic_key').startswith('W_X')):
options = {
'method': 'POST',
'body': json.dumps({
"comm": {
"fPersonality": "0",
"tmeLoginType": "1",
"tmeLoginMethod": "1",
"qq": "",
"authst": "",
"ct": "11",
"cv": "12080008",
"v": "12080008",
"tmeAppID": "qqmusic"
},
"req1": {
"module": "music.login.LoginServer",
"method": "Login",
"param": {
"code": "",
"openid": "",
"refresh_token": "",
"str_musicid": str(config.read_config('module.tx.user.uin')),
"musickey": config.read_config('module.tx.user.qqmusic_key'),
"unionid": "",
"refresh_key": "",
"loginMode": 2
}
}
})
}
signature = sign(options['body'])
req = await Httpx.AsyncRequest(f'https://u.y.qq.com/cgi-bin/musics.fcg?sign={signature}', options)
body = req.json()
if (body['req1']['code'] != 0):
logger.warning('刷新登录失败, code: ' +
str(body['req1']['code']) + f'\n响应体: {body}')
return
else:
logger.info('刷新登录成功')
config.write_config('module.tx.user.uin',
body['req1']['data']['musicid'])
logger.info('已通过相应数据更新uin')
config.write_config('module.tx.user.qqmusic_key',
body['req1']['data']['musickey'])
logger.info('已通过相应数据更新qqmusic_key')
elif (config.read_config('module.tx.user.qqmusic_key').startswith('Q_H_L')):
options = {
'method': 'POST',
'body': json.dumps({
'req1': {
'module': 'QQConnectLogin.LoginServer',
'method': 'QQLogin',
'param': {
'expired_in': 7776000,
'musicid': int(config.read_config('module.tx.user.uin')),
'musickey': config.read_config('module.tx.user.qqmusic_key')
}
}
})
}
signature = sign(options['body'])
req = await Httpx.AsyncRequest(f'https://u6.y.qq.com/cgi-bin/musics.fcg?sign={signature}', options)
body = req.json()
if (body['req1']['code'] != 0):
logger.warning('刷新登录失败, code: ' +
str(body['req1']['code']) + f'\n响应体: {body}')
return
else:
logger.info('刷新登录成功')
config.write_config('module.tx.user.uin',
body['req1']['data']['musicid'])
logger.info('已通过相应数据更新uin')
config.write_config('module.tx.user.qqmusic_key',
body['req1']['data']['musickey'])
logger.info('已通过相应数据更新qqmusic_key')
else:
logger.error('未知的qqmusic_key格式')
if (config.read_config('module.tx.refresh_login.enable')):
scheduler.append('qqmusic_refresh_login', refresh,
config.read_config('module.tx.refresh_login.interval'))

View File

@ -50,10 +50,8 @@ tools = createObject({
'Q000': 'dolby',
'AI00': 'master'
},
"key": config.read_config("module.tx.user.qqmusic_key"),
"loginuin": config.read_config("module.tx.user.uin"),
"guid": config.read_config("module.tx.vkeyserver.guid"),
"uin": config.read_config("module.tx.vkeyserver.uin"),
"cdnaddr": config.read_config("module.tx.cdnaddr") if config.read_config("module.tx.cdnaddr") else 'http://ws.stream.qqmusic.qq.com/',
})