From aad3a7142749c8381bc41a6b1d2004fd217799d6 Mon Sep 17 00:00:00 2001 From: helloplhm-qwq Date: Sat, 11 Nov 2023 21:12:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20tx=E6=BA=90cdn=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/tx/__init__.py | 3 ++- common/config.py | 33 +++++++++++++++++++-------------- common/log.py | 1 - 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/apis/tx/__init__.py b/apis/tx/__init__.py index aa141cb..b4be9a6 100644 --- a/apis/tx/__init__.py +++ b/apis/tx/__init__.py @@ -39,6 +39,7 @@ tools = jsobject({ "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/', }) @@ -81,4 +82,4 @@ async def url(songId, quality): # js const { purl } = data.req_0.data.midurlinfo[0] if (not body.req_0.data.midurlinfo[0]['purl']): raise FailedException('failed') - return 'http://ws.stream.qqmusic.qq.com/' + body.req_0.data.midurlinfo[0]['purl'] + return tools.cdnaddr + body.req_0.data.midurlinfo[0]['purl'] diff --git a/common/config.py b/common/config.py index 5f546df..5d69eff 100644 --- a/common/config.py +++ b/common/config.py @@ -141,7 +141,8 @@ default = { "qqmusic_key": "", "uin": "", "_uin-desc": "key对应的QQ号" - } + }, + "cdnaddr": "http://ws.stream.qqmusic.qq.com/", }, "wy": { "desc": "网易云音乐相关配置", @@ -360,21 +361,25 @@ def push_to_list(key, obj): def read_config(key): - config = variable.config - keys = key.split('.') - value = config - for k in keys: - if isinstance(value, dict): - if k not in value and keys.index(k) != len(keys) - 1: - value[k] = {} - elif k not in value and keys.index(k) == len(keys) - 1: + try: + config = variable.config + keys = key.split('.') + value = config + for k in keys: + if isinstance(value, dict): + if k not in value and keys.index(k) != len(keys) - 1: + value[k] = {} + elif k not in value and keys.index(k) == len(keys) - 1: + value = None + value = value[k] + else: value = None - value = value[k] - else: - value = None - break + break - return value + return value + except: + logger.warning(f'配置文件{key}不存在') + return None def initConfig(): diff --git a/common/log.py b/common/log.py index 886829d..c18c8cf 100644 --- a/common/log.py +++ b/common/log.py @@ -11,7 +11,6 @@ import logging import colorlog import os -import traceback from pygments import highlight from pygments.lexers import PythonLexer from pygments.formatters import TerminalFormatter