fix: 修复LRC文件读取歌词

This commit is contained in:
helloplhm-qwq 2024-02-04 16:17:54 +08:00
parent a55da25de5
commit 35f1fe513a
No known key found for this signature in database
GPG Key ID: 6BE1B64B905567C7
2 changed files with 18 additions and 3 deletions

View File

@ -143,7 +143,7 @@ def getAudioMeta(filepath):
audio = mutagen.File(filepath)
if not audio:
return None
logger.info(audio.items())
logger.debug(audio.items())
if (filepath.lower().endswith('.mp3')):
cover = audio.get('APIC:')
if (cover):
@ -161,8 +161,20 @@ def getAudioMeta(filepath):
album = album.text
if (lyric):
lyric = lyric.text
else:
lyric = [None]
if (not lyric):
if (os.path.isfile(os.path.splitext(filepath)[0] + '.lrc')):
with open(os.path.splitext(filepath)[0] + '.lrc', 'r', encoding='utf-8') as f:
t = f.read().replace('\ufeff', '')
logger.debug(t)
lyric = filterLyricLine(t)
logger.debug(lyric)
if (not checkLyricValid(lyric)):
lyric = [None]
else:
lyric = [lyric]
f.close()
else:
lyric = [None]
else:
cover = audio.get('cover')
if (cover):
@ -182,6 +194,8 @@ def getAudioMeta(filepath):
lyric = filterLyricLine(f.read())
if (not checkLyricValid(lyric)):
lyric = [None]
else:
lyric = [lyric]
f.close()
else:
lyric = [None]

View File

@ -159,6 +159,7 @@ async def handle_local(request):
t = request.match_info.get('type')
data['t'] = t
except:
logger.info(traceback.format_exc())
return handleResult({'code': 6, 'msg': '请求参数有错', 'data': None}, 404)
if (data['t'] == 'u'):
if (data['p'] in list(localMusic.map.keys())):