Skip to content

Commit

Permalink
chore: 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
helloplhm-qwq committed Dec 16, 2023
1 parent 901d2ab commit 34eb840
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 25 deletions.
11 changes: 9 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion common/EncryptUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions common/Httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)):
Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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请求失败的情况
Expand Down
1 change: 0 additions & 1 deletion common/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions common/lxsecurity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('//', '/')
Expand Down
3 changes: 1 addition & 2 deletions common/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

# 一个简单的循环任务调度器

Expand Down Expand Up @@ -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...")
Expand Down
3 changes: 0 additions & 3 deletions common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@
# - 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
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)
Expand Down
1 change: 0 additions & 1 deletion common/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions main-flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
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')
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion modules/kw/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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过来的,不进行注释
# 下方为原文件版权声明,在此进行保留
Expand Down
1 change: 0 additions & 1 deletion modules/mg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions modules/wy/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 34eb840

Please sign in to comment.