Skip to content

Commit

Permalink
Merge pull request #62 from katagomo/main
Browse files Browse the repository at this point in the history
修复cover请求失败导致的报错
  • Loading branch information
HisAtri authored Jul 16, 2024
2 parents cfb4dac + ba5759f commit d3de9c1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
3 changes: 3 additions & 0 deletions api/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from flask import request, abort, redirect
from urllib.parse import unquote_plus
from mygo.devtools import no_error

from mod import searchx

Expand Down Expand Up @@ -33,6 +34,7 @@ def local_cover_search(title: str, artist: str, album: str):

@app.route('/cover', methods=['GET'])
@cache.cached(timeout=86400, key_prefix=make_cache_key)
@no_error(exceptions=AttributeError)
def cover_api():
title = unquote_plus(request.args.get('title'))
artist = unquote_plus(request.args.get('artist', ''))
Expand All @@ -53,6 +55,7 @@ def cover_api():

@v1_bp.route('/cover/<path:s_type>', methods=['GET'])
@cache.cached(timeout=86400, key_prefix=make_cache_key)
@no_error(exceptions=AttributeError)
def cover_new(s_type):
__endpoints__ = ["music", "album", "artist"]
if s_type not in __endpoints__:
Expand Down
28 changes: 26 additions & 2 deletions api/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from . import *

from flask import request, render_template_string
from flask import request, render_template_string, abort

from mod import tag
from mod.auth import webui
Expand All @@ -12,7 +12,6 @@

@app.route('/tag', methods=['POST', 'PUT'])
@app.route('/confirm', methods=['POST', 'PUT'])
@v1_bp.route('/tag', methods=['POST', 'PUT'])
def setTag():
match require_auth(request=request, permission='rw'):
case -1:
Expand Down Expand Up @@ -49,3 +48,28 @@ 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/<path:location>', 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))
2 changes: 1 addition & 1 deletion mod/searchx/kugou.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from mod import textcompare
from mod import tools

from wowotou.devtools import no_error
from mygo.devtools import no_error

headers = {'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 '
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ aiohttp~=3.9.1
Pillow~=10.1.0
pyaes~=1.6.1
Werkzeug~=3.0.1
wowotou~=1.0.1
mygo~=1.0.0

0 comments on commit d3de9c1

Please sign in to comment.