mirror of
https://github.com/MeoProject/lx-music-api-server.git
synced 2025-05-23 19:17:41 +08:00
chore: 优化代码
This commit is contained in:
parent
901d2ab838
commit
34eb8403b5
11
build.py
11
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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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请求失败的情况
|
||||
|
@ -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
|
||||
|
@ -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('//', '/')
|
||||
|
@ -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...")
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
|
4
main.py
4
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):
|
||||
|
@ -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
|
||||
|
@ -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过来的,不进行注释
|
||||
# 下方为原文件版权声明,在此进行保留
|
||||
|
@ -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',
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user