From 34eb8403b5cb0e118fc058e8f221977a3a6ec84d Mon Sep 17 00:00:00 2001 From: helloplhm-qwq Date: Sat, 16 Dec 2023 16:29:09 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.py | 11 +++++++++-- common/EncryptUtils.py | 1 - common/Httpx.py | 8 ++++++-- common/config.py | 1 - common/exceptions.py | 1 - common/log.py | 1 - common/lxsecurity.py | 2 -- common/scheduler.py | 3 +-- common/utils.py | 3 --- common/variable.py | 1 - main-flask.py | 4 ++-- main.py | 4 ++-- modules/__init__.py | 2 +- modules/kw/encrypt.py | 1 - modules/mg/__init__.py | 1 - modules/wy/encrypt.py | 3 +-- 16 files changed, 22 insertions(+), 25 deletions(-) diff --git a/build.py b/build.py index 7a26abd..d281655 100644 --- a/build.py +++ b/build.py @@ -17,11 +17,14 @@ def get_changelog(): docsMsg = [] buildMsg = [] otherMsg = [] + noticeMsg = [] unknownMsg = [] for msg in res: - if (re.match('[a-f0-9]*.(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\:', msg[1:-1])): + if (re.match('[a-f0-9]*.(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|notice)\:', msg[1:-1])): msg = msg[1:-1] - if msg[8:].startswith('feat:'): + if msg[8:].startswith('notice:'): + noticeMsg.append(msg) + elif msg[8:].startswith('feat:'): featMsg.append(msg) elif msg[8:].startswith('fix:'): fixMsg.append(msg) @@ -36,6 +39,10 @@ def get_changelog(): unknownMsg.append(msg) # final Nres = '' + if (len(noticeMsg) > 0): + Nres += '## 公告\n' + for msg in noticeMsg: + Nres += f'- {msg}\n' if (len(featMsg) > 0): Nres += '## 功能更新\n' for msg in featMsg: diff --git a/common/EncryptUtils.py b/common/EncryptUtils.py index 2373592..aaa1f0a 100644 --- a/common/EncryptUtils.py +++ b/common/EncryptUtils.py @@ -6,7 +6,6 @@ # - license: MIT - # ---------------------------------------- # This file is part of the "lx-music-api-server" project. -# Do not edit except you know what you are doing. from Crypto.Cipher import AES, DES import binascii diff --git a/common/Httpx.py b/common/Httpx.py index fba6edb..053a29a 100644 --- a/common/Httpx.py +++ b/common/Httpx.py @@ -6,7 +6,6 @@ # - license: MIT - # ---------------------------------------- # This file is part of the "lx-music-api-server" project. -# Do not edit except you know what you are doing. # import aiohttp # import asyncio @@ -143,6 +142,8 @@ def request(url, options = {}): options['data'] = convert_dict_to_form_string(options['form']) options.pop('form') options['headers']['Content-Type'] = 'application/x-www-form-urlencoded' + if (isinstance(options['data'], dict)): + options['data'] = json.dumps(options['data']) # 进行请求 try: logger.info("-----start----- " + url) @@ -152,7 +153,7 @@ def request(url, options = {}): raise e # 请求后记录 logger.debug(f'Request to {url} succeed with code {req.status_code}') - if (req.content.startswith(b'\x78\x9c')): # zlib header + if (req.content.startswith(b'\x78\x9c') or req.content.startswith(b'\x78\x01')): # zlib headers try: decompressed = zlib.decompress(req.content) if (is_valid_utf8(decompressed)): @@ -172,6 +173,9 @@ def request(url, options = {}): expire_time = (cache_info if isinstance(cache_info, int) else 3600) + int(time.time()) config.updateCache("httpx", cache_key, {"expire": True, "time": expire_time, "data": utils.createBase64Encode(cache_data)}) logger.debug("缓存已更新: " + url) + def _json(): + return json.loads(req.content) + setattr(req, 'json', _json) # 返回请求 return req diff --git a/common/config.py b/common/config.py index b9c9004..a8c1283 100644 --- a/common/config.py +++ b/common/config.py @@ -6,7 +6,6 @@ # - license: MIT - # ---------------------------------------- # This file is part of the "lx-music-api-server" project. -# Do not edit except you know what you are doing. import ujson as json import time diff --git a/common/exceptions.py b/common/exceptions.py index 426aee8..c4e5a6d 100644 --- a/common/exceptions.py +++ b/common/exceptions.py @@ -6,7 +6,6 @@ # - license: MIT - # ---------------------------------------- # This file is part of the "lx-music-api-server" project. -# Do not edit except you know what you are doing. class FailedException(Exception): # 此错误用于处理代理API请求失败的情况 diff --git a/common/log.py b/common/log.py index 65b39c9..f39959f 100644 --- a/common/log.py +++ b/common/log.py @@ -6,7 +6,6 @@ # - license: MIT - # ---------------------------------------- # This file is part of the "lx-music-api-server" project. -# Do not edit except you know what you are doing. import logging import colorlog diff --git a/common/lxsecurity.py b/common/lxsecurity.py index 9a3e4b1..6db16f2 100644 --- a/common/lxsecurity.py +++ b/common/lxsecurity.py @@ -6,14 +6,12 @@ # - license: MIT - # ---------------------------------------- # This file is part of the "lx-music-api-server" project. -# Do not edit except you know what you are doing. from . import utils import ujson as json import binascii import re -# js: path = url.replace(/^https?:\/\/[\w.:]+\//, '/') def checklxmheader(lxm, url): try: path = url.replace(re.findall(r'(?:https?:\/\/[\w.:]+\/)', url)[0], '/').replace('//', '/') diff --git a/common/scheduler.py b/common/scheduler.py index 9626f86..21dd4ab 100644 --- a/common/scheduler.py +++ b/common/scheduler.py @@ -6,7 +6,6 @@ # - license: MIT - # ---------------------------------------- # This file is part of the "lx-music-api-server" project. -# Do not edit except you know what you are doing. # 一个简单的循环任务调度器 @@ -52,7 +51,7 @@ def thread_runner(): if t.check_available(): t.latest_execute = int(time.time()) threading.Thread(target = t.run).start() - time.sleep(5) + time.sleep(1) def run(): logger.debug("scheduler thread starting...") diff --git a/common/utils.py b/common/utils.py index 48ef17d..bc58cff 100644 --- a/common/utils.py +++ b/common/utils.py @@ -6,7 +6,6 @@ # - license: MIT - # ---------------------------------------- # This file is part of the "lx-music-api-server" project. -# Do not edit except you know what you are doing. import platform import binascii @@ -14,11 +13,9 @@ import builtins import base64 import zlib import re -import ujson as json import xmltodict from urllib.parse import quote from hashlib import md5 as handleCreateMD5 -# from flask import Response def createBase64Encode(data_bytes): encoded_data = base64.b64encode(data_bytes) diff --git a/common/variable.py b/common/variable.py index 82e2050..6798233 100644 --- a/common/variable.py +++ b/common/variable.py @@ -6,7 +6,6 @@ # - license: MIT - # ---------------------------------------- # This file is part of the "lx-music-api-server" project. -# Do not edit except you know what you are doing. import os import ujson as json diff --git a/main-flask.py b/main-flask.py index 759c7b6..d1c08d9 100644 --- a/main-flask.py +++ b/main-flask.py @@ -25,15 +25,15 @@ flask_logger = log.log('flask') logging.getLogger('werkzeug').addHandler(log.LogHelper(flask_logger)) logger = log.log("main") -from common import utils from common import lxsecurity from common import Httpx from modules import handleApiRequest from flask import Response +import threading import ujson as json import traceback import time -Httpx.checkcn() +threading.Thread(target=Httpx.checkcn).start() def handleResult(dic): return Response(json.dumps(dic, indent=2, ensure_ascii=False), mimetype='application/json') diff --git a/main.py b/main.py index 0bb6646..c875453 100644 --- a/main.py +++ b/main.py @@ -12,12 +12,12 @@ from aiohttp import web from common import config from common import lxsecurity -from common import utils from common import log from common import Httpx from modules import handleApiRequest from aiohttp.web import Response import ujson as json +import threading import traceback import time @@ -27,7 +27,7 @@ def handleResult(dic, status = 200): logger = log.log("main") aiologger = log.log('aiohttp_web') -Httpx.checkcn() +threading.Thread(target=Httpx.checkcn).start() # check request info before start async def handle_before_request(app, handler): diff --git a/modules/__init__.py b/modules/__init__.py index 7b70a33..7add17d 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -6,12 +6,12 @@ # - license: MIT - # ---------------------------------------- # This file is part of the "lx-music-api-server" project. -# Do not edit except you konw what you are doing. from common.exceptions import FailedException from common.utils import require from common import log from common import config +# 从.引入的包并没有在代码中直接使用,但是是用require在请求时进行引入的,不要动 from . import kw from . import mg from . import kg diff --git a/modules/kw/encrypt.py b/modules/kw/encrypt.py index bd8e8c3..f3303a0 100644 --- a/modules/kw/encrypt.py +++ b/modules/kw/encrypt.py @@ -6,7 +6,6 @@ # - license: MIT - # ---------------------------------------- # This file is part of the "lx-music-api-server" project. -# Do not edit except you know what you are doing. # KuwoDES加密实现,CV过来的,不进行注释 # 下方为原文件版权声明,在此进行保留 diff --git a/modules/mg/__init__.py b/modules/mg/__init__.py index 6dea691..9052f22 100644 --- a/modules/mg/__init__.py +++ b/modules/mg/__init__.py @@ -10,7 +10,6 @@ from common import Httpx from common import config from common.exceptions import FailedException -import traceback tools = { 'url': 'https://app.c.nf.migu.cn/MIGUM2.0/strategy/listen-url/v2.4?toneFlag=__quality__&songId=__songId__&resourceType=2', diff --git a/modules/wy/encrypt.py b/modules/wy/encrypt.py index 890b130..2fcf03b 100644 --- a/modules/wy/encrypt.py +++ b/modules/wy/encrypt.py @@ -7,11 +7,10 @@ # ---------------------------------------- # This file is part of the "lx-music-api-server" project. -from json import dumps +from ujson import dumps from os import urandom from base64 import b64encode from binascii import hexlify -from hashlib import md5 from Crypto.Cipher import AES from common import utils