diff --git a/api/tag.py b/api/tag.py index f1dba6e..571ef4f 100644 --- a/api/tag.py +++ b/api/tag.py @@ -12,7 +12,7 @@ @app.route('/tag', methods=['POST', 'PUT']) @app.route('/confirm', methods=['POST', 'PUT']) -def setTag(): +def set_tag(): match require_auth(request=request, permission='rw'): case -1: logger.error("Unauthorized access: 未经授权的用户请求修改标签") @@ -51,28 +51,3 @@ def setTag(): except Exception as e: return {"code": 500, "error": str(e)}, 500 return {"code": 200, "log": f"Successfully edited file {audio_path}"}, 200 - - -@v1_bp.route('/tag/', methods=['POST', 'PUT']) -def setTagLocal(location: str): - if location not in ('local', 'writein'): - return {"code": 404, "error": "Unknown endpoint"}, 404 - - match require_auth(request=request, permission='rw'): - case -1: - return render_template_string(webui.error()), 403 - case -2: - return render_template_string(webui.error()), 421 - - music_data = request.json - if not os.path.exists(file_path := music_data.get("path")): - return {"code": 404, "error": "File not found"}, 404 - - def remove_extension(filename: str) -> str: - last_dot_index = filename.rfind('.') - if last_dot_index != -1: - return filename[:last_dot_index] - else: - return filename - - r_file_name: str = remove_extension(os.path.basename(file_path)) diff --git a/app.py b/app.py index 2361b7a..1955da0 100644 --- a/app.py +++ b/app.py @@ -22,7 +22,7 @@ def run_server(debug=False): debugger.log("info", f"Version: {args.version}") if args.auth: debugger.log("info", f"Auth: {args.auth}") - app.run(host='0.0.0.0', port=args.port, debug=True) + app.run(host='*', port=args.port, debug=True) if __name__ == '__main__': diff --git a/mod/args/__init__.py b/mod/args/__init__.py index 0ecc767..6912472 100644 --- a/mod/args/__init__.py +++ b/mod/args/__init__.py @@ -29,7 +29,7 @@ def first(*args): class DefaultConfig: def __init__(self): - self.ip = '0.0.0.0' + self.ip = '*' self.port = 28883 @@ -41,7 +41,7 @@ class ConfigFile: def __init__(self): json_config = { "server": { - "ip": "0.0.0.0", + "ip": "*", "port": 28883 }, "auth": {} @@ -60,7 +60,7 @@ def __init__(self): self.auth: dict = json_config.get("auth", {}) self.server = json_config.get("server", {}) self.port = self.server.get("port", 0) - self.ip = self.server.get("ip", "0.0.0.0") + self.ip = self.server.get("ip", "*") # 环境变量定义值 diff --git a/mod/auth/authentication.py b/mod/auth/authentication.py index e0679b8..47b6bf3 100644 --- a/mod/auth/authentication.py +++ b/mod/auth/authentication.py @@ -3,7 +3,6 @@ from . import cookie from mod.args import GlobalArgs - args = GlobalArgs() diff --git a/mod/check_update.py b/mod/check_update.py index e902bd6..22b4349 100644 --- a/mod/check_update.py +++ b/mod/check_update.py @@ -58,7 +58,7 @@ def version_upper(latest: str, app_version: str) -> bool: def check_update(version): - logger.info(f"正在检查更新,当前版本") + logger.info(f"正在检查更新,当前版本为 {version}") try: latest_version = get_version() if version_upper(latest_version, version): diff --git a/mod/searchx/kugou.py b/mod/searchx/kugou.py index 5d603dc..388381b 100644 --- a/mod/searchx/kugou.py +++ b/mod/searchx/kugou.py @@ -14,13 +14,13 @@ from mygo.devtools import no_error -headers = {'User-Agent': '{"percent": 21.4, "useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' +headers: dict = {'User-Agent': '{"percent": 21.4, "useragent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36", "system": "Chrome ' '116.0 Win10", "browser": "chrome", "version": 116.0, "os": "win10"}', } logger = logging.getLogger(__name__) -async def get_cover(session, m_hash, m_id): +async def get_cover(session: aiohttp.ClientSession, m_hash: str, m_id: int|str) -> str: def _dfid(num): random_str = ''.join(random.sample((string.ascii_letters + string.digits), num)) return random_str @@ -56,9 +56,9 @@ async def a_search(title='', artist='', album=''): f"http://mobilecdn.kugou.com/api/v3/search/song?format=json&keyword={' '.join([item for item in [title, artist, album] if item])}&page=1&pagesize=2&showtype=1", headers=headers) as response: if response.status == 200: - song_info_t = await response.text() - song_info = json.loads(song_info_t) - song_info = song_info["data"]["info"] + song_info_t: str = await response.text() + song_info: dict = json.loads(song_info_t) + song_info: list[dict] = song_info["data"]["info"] if len(song_info) >= 1: for song_item in song_info: song_name = song_item["songname"] @@ -68,7 +68,7 @@ async def a_search(title='', artist='', album=''): album_name = song_item.get("album_name", "") title_conform_ratio = textcompare.association(title, song_name) artist_conform_ratio = textcompare.assoc_artists(artist, singer_name) - ratio = (title_conform_ratio * (artist_conform_ratio+1)/2) ** 0.5 + ratio: float = (title_conform_ratio * (artist_conform_ratio+1)/2) ** 0.5 if ratio >= 0.2: async with session.get( f"https://krcs.kugou.com/search?ver=1&man=yes&client=mobi&keyword=&duration=&hash={song_hash}&album_audio_id=", @@ -86,7 +86,7 @@ async def a_search(title='', artist='', album=''): lyrics_encode = lyrics_data["content"] # 这里是Base64编码的数据 lrc_text = tools.standard_lrc(base64.b64decode(lyrics_encode).decode('utf-8')) # 这里解码 # 结构化JSON数据 - music_json_data = { + music_json_data: dict = { "title": song_name, "album": album_name, "artists": singer_name, @@ -103,7 +103,7 @@ async def a_search(title='', artist='', album=''): break else: return None - sort_li = sorted(result_list, key=lambda x: x['ratio'], reverse=True) + sort_li: list[dict] = sorted(result_list, key=lambda x: x['ratio'], reverse=True) return [i.get('data') for i in sort_li] diff --git a/src/index.html b/src/index.html index 8eadcfa..d8a56ce 100644 --- a/src/index.html +++ b/src/index.html @@ -24,10 +24,6 @@ Github -
- 服务器赞助 -