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 = []
|
docsMsg = []
|
||||||
buildMsg = []
|
buildMsg = []
|
||||||
otherMsg = []
|
otherMsg = []
|
||||||
|
noticeMsg = []
|
||||||
unknownMsg = []
|
unknownMsg = []
|
||||||
for msg in res:
|
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]
|
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)
|
featMsg.append(msg)
|
||||||
elif msg[8:].startswith('fix:'):
|
elif msg[8:].startswith('fix:'):
|
||||||
fixMsg.append(msg)
|
fixMsg.append(msg)
|
||||||
@ -36,6 +39,10 @@ def get_changelog():
|
|||||||
unknownMsg.append(msg)
|
unknownMsg.append(msg)
|
||||||
# final
|
# final
|
||||||
Nres = ''
|
Nres = ''
|
||||||
|
if (len(noticeMsg) > 0):
|
||||||
|
Nres += '## 公告\n'
|
||||||
|
for msg in noticeMsg:
|
||||||
|
Nres += f'- {msg}\n'
|
||||||
if (len(featMsg) > 0):
|
if (len(featMsg) > 0):
|
||||||
Nres += '## 功能更新\n'
|
Nres += '## 功能更新\n'
|
||||||
for msg in featMsg:
|
for msg in featMsg:
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
# - license: MIT -
|
# - license: MIT -
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# 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
|
from Crypto.Cipher import AES, DES
|
||||||
import binascii
|
import binascii
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
# - license: MIT -
|
# - license: MIT -
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# This file is part of the "lx-music-api-server" project.
|
||||||
# Do not edit except you know what you are doing.
|
|
||||||
|
|
||||||
# import aiohttp
|
# import aiohttp
|
||||||
# import asyncio
|
# import asyncio
|
||||||
@ -143,6 +142,8 @@ def request(url, options = {}):
|
|||||||
options['data'] = convert_dict_to_form_string(options['form'])
|
options['data'] = convert_dict_to_form_string(options['form'])
|
||||||
options.pop('form')
|
options.pop('form')
|
||||||
options['headers']['Content-Type'] = 'application/x-www-form-urlencoded'
|
options['headers']['Content-Type'] = 'application/x-www-form-urlencoded'
|
||||||
|
if (isinstance(options['data'], dict)):
|
||||||
|
options['data'] = json.dumps(options['data'])
|
||||||
# 进行请求
|
# 进行请求
|
||||||
try:
|
try:
|
||||||
logger.info("-----start----- " + url)
|
logger.info("-----start----- " + url)
|
||||||
@ -152,7 +153,7 @@ def request(url, options = {}):
|
|||||||
raise e
|
raise e
|
||||||
# 请求后记录
|
# 请求后记录
|
||||||
logger.debug(f'Request to {url} succeed with code {req.status_code}')
|
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:
|
try:
|
||||||
decompressed = zlib.decompress(req.content)
|
decompressed = zlib.decompress(req.content)
|
||||||
if (is_valid_utf8(decompressed)):
|
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())
|
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)})
|
config.updateCache("httpx", cache_key, {"expire": True, "time": expire_time, "data": utils.createBase64Encode(cache_data)})
|
||||||
logger.debug("缓存已更新: " + url)
|
logger.debug("缓存已更新: " + url)
|
||||||
|
def _json():
|
||||||
|
return json.loads(req.content)
|
||||||
|
setattr(req, 'json', _json)
|
||||||
# 返回请求
|
# 返回请求
|
||||||
return req
|
return req
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
# - license: MIT -
|
# - license: MIT -
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# 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 ujson as json
|
||||||
import time
|
import time
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
# - license: MIT -
|
# - license: MIT -
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# This file is part of the "lx-music-api-server" project.
|
||||||
# Do not edit except you know what you are doing.
|
|
||||||
|
|
||||||
class FailedException(Exception):
|
class FailedException(Exception):
|
||||||
# 此错误用于处理代理API请求失败的情况
|
# 此错误用于处理代理API请求失败的情况
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
# - license: MIT -
|
# - license: MIT -
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# This file is part of the "lx-music-api-server" project.
|
||||||
# Do not edit except you know what you are doing.
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import colorlog
|
import colorlog
|
||||||
|
@ -6,14 +6,12 @@
|
|||||||
# - license: MIT -
|
# - license: MIT -
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# This file is part of the "lx-music-api-server" project.
|
||||||
# Do not edit except you know what you are doing.
|
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
import ujson as json
|
import ujson as json
|
||||||
import binascii
|
import binascii
|
||||||
import re
|
import re
|
||||||
|
|
||||||
# js: path = url.replace(/^https?:\/\/[\w.:]+\//, '/')
|
|
||||||
def checklxmheader(lxm, url):
|
def checklxmheader(lxm, url):
|
||||||
try:
|
try:
|
||||||
path = url.replace(re.findall(r'(?:https?:\/\/[\w.:]+\/)', url)[0], '/').replace('//', '/')
|
path = url.replace(re.findall(r'(?:https?:\/\/[\w.:]+\/)', url)[0], '/').replace('//', '/')
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
# - license: MIT -
|
# - license: MIT -
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# 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():
|
if t.check_available():
|
||||||
t.latest_execute = int(time.time())
|
t.latest_execute = int(time.time())
|
||||||
threading.Thread(target = t.run).start()
|
threading.Thread(target = t.run).start()
|
||||||
time.sleep(5)
|
time.sleep(1)
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
logger.debug("scheduler thread starting...")
|
logger.debug("scheduler thread starting...")
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
# - license: MIT -
|
# - license: MIT -
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# This file is part of the "lx-music-api-server" project.
|
||||||
# Do not edit except you know what you are doing.
|
|
||||||
|
|
||||||
import platform
|
import platform
|
||||||
import binascii
|
import binascii
|
||||||
@ -14,11 +13,9 @@ import builtins
|
|||||||
import base64
|
import base64
|
||||||
import zlib
|
import zlib
|
||||||
import re
|
import re
|
||||||
import ujson as json
|
|
||||||
import xmltodict
|
import xmltodict
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
from hashlib import md5 as handleCreateMD5
|
from hashlib import md5 as handleCreateMD5
|
||||||
# from flask import Response
|
|
||||||
|
|
||||||
def createBase64Encode(data_bytes):
|
def createBase64Encode(data_bytes):
|
||||||
encoded_data = base64.b64encode(data_bytes)
|
encoded_data = base64.b64encode(data_bytes)
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
# - license: MIT -
|
# - license: MIT -
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# This file is part of the "lx-music-api-server" project.
|
||||||
# Do not edit except you know what you are doing.
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import ujson as json
|
import ujson as json
|
||||||
|
@ -25,15 +25,15 @@ flask_logger = log.log('flask')
|
|||||||
logging.getLogger('werkzeug').addHandler(log.LogHelper(flask_logger))
|
logging.getLogger('werkzeug').addHandler(log.LogHelper(flask_logger))
|
||||||
logger = log.log("main")
|
logger = log.log("main")
|
||||||
|
|
||||||
from common import utils
|
|
||||||
from common import lxsecurity
|
from common import lxsecurity
|
||||||
from common import Httpx
|
from common import Httpx
|
||||||
from modules import handleApiRequest
|
from modules import handleApiRequest
|
||||||
from flask import Response
|
from flask import Response
|
||||||
|
import threading
|
||||||
import ujson as json
|
import ujson as json
|
||||||
import traceback
|
import traceback
|
||||||
import time
|
import time
|
||||||
Httpx.checkcn()
|
threading.Thread(target=Httpx.checkcn).start()
|
||||||
|
|
||||||
def handleResult(dic):
|
def handleResult(dic):
|
||||||
return Response(json.dumps(dic, indent=2, ensure_ascii=False), mimetype='application/json')
|
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 aiohttp import web
|
||||||
from common import config
|
from common import config
|
||||||
from common import lxsecurity
|
from common import lxsecurity
|
||||||
from common import utils
|
|
||||||
from common import log
|
from common import log
|
||||||
from common import Httpx
|
from common import Httpx
|
||||||
from modules import handleApiRequest
|
from modules import handleApiRequest
|
||||||
from aiohttp.web import Response
|
from aiohttp.web import Response
|
||||||
import ujson as json
|
import ujson as json
|
||||||
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ def handleResult(dic, status = 200):
|
|||||||
logger = log.log("main")
|
logger = log.log("main")
|
||||||
aiologger = log.log('aiohttp_web')
|
aiologger = log.log('aiohttp_web')
|
||||||
|
|
||||||
Httpx.checkcn()
|
threading.Thread(target=Httpx.checkcn).start()
|
||||||
|
|
||||||
# check request info before start
|
# check request info before start
|
||||||
async def handle_before_request(app, handler):
|
async def handle_before_request(app, handler):
|
||||||
|
@ -6,12 +6,12 @@
|
|||||||
# - license: MIT -
|
# - license: MIT -
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# 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.exceptions import FailedException
|
||||||
from common.utils import require
|
from common.utils import require
|
||||||
from common import log
|
from common import log
|
||||||
from common import config
|
from common import config
|
||||||
|
# 从.引入的包并没有在代码中直接使用,但是是用require在请求时进行引入的,不要动
|
||||||
from . import kw
|
from . import kw
|
||||||
from . import mg
|
from . import mg
|
||||||
from . import kg
|
from . import kg
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
# - license: MIT -
|
# - license: MIT -
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# This file is part of the "lx-music-api-server" project.
|
# This file is part of the "lx-music-api-server" project.
|
||||||
# Do not edit except you know what you are doing.
|
|
||||||
|
|
||||||
# KuwoDES加密实现,CV过来的,不进行注释
|
# KuwoDES加密实现,CV过来的,不进行注释
|
||||||
# 下方为原文件版权声明,在此进行保留
|
# 下方为原文件版权声明,在此进行保留
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
from common import Httpx
|
from common import Httpx
|
||||||
from common import config
|
from common import config
|
||||||
from common.exceptions import FailedException
|
from common.exceptions import FailedException
|
||||||
import traceback
|
|
||||||
|
|
||||||
tools = {
|
tools = {
|
||||||
'url': 'https://app.c.nf.migu.cn/MIGUM2.0/strategy/listen-url/v2.4?toneFlag=__quality__&songId=__songId__&resourceType=2',
|
'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.
|
# This file is part of the "lx-music-api-server" project.
|
||||||
|
|
||||||
from json import dumps
|
from ujson import dumps
|
||||||
from os import urandom
|
from os import urandom
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
from hashlib import md5
|
|
||||||
from Crypto.Cipher import AES
|
from Crypto.Cipher import AES
|
||||||
from common import utils
|
from common import utils
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user