Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加ipv6监听 部分输出优化 #68

Merged
merged 5 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions api/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: 未经授权的用户请求修改标签")
Expand Down Expand Up @@ -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/<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 app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
6 changes: 3 additions & 3 deletions mod/args/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def first(*args):

class DefaultConfig:
def __init__(self):
self.ip = '0.0.0.0'
self.ip = '*'
self.port = 28883


Expand All @@ -41,7 +41,7 @@ class ConfigFile:
def __init__(self):
json_config = {
"server": {
"ip": "0.0.0.0",
"ip": "*",
"port": 28883
},
"auth": {}
Expand All @@ -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", "*")


# 环境变量定义值
Expand Down
1 change: 0 additions & 1 deletion mod/auth/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from . import cookie
from mod.args import GlobalArgs


args = GlobalArgs()


Expand Down
2 changes: 1 addition & 1 deletion mod/check_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions mod/searchx/kugou.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand All @@ -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=",
Expand All @@ -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,
Expand All @@ -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]


Expand Down
4 changes: 0 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
<a class="nav-link text-dark" href="https://github.com/HisAtri/LrcApi"><i class="bi bi-github"></i> Github <i
class="bi bi-box-arrow-up-right"></i></a>
</div>
<div style="display: inline-block;float: right;">
<a class="nav-link text-dark" href="https://www.ejiabest.cn/"> 服务器赞助 <i
class="bi bi-box-arrow-up-right"></i></a>
</div>
</div>
</div>
</nav>
Expand Down
Loading