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) audio = mutagen.File(filepath)
if not audio: if not audio:
return None return None
logger.info(audio.items()) logger.debug(audio.items())
if (filepath.lower().endswith('.mp3')): if (filepath.lower().endswith('.mp3')):
cover = audio.get('APIC:') cover = audio.get('APIC:')
if (cover): if (cover):
@ -161,6 +161,18 @@ def getAudioMeta(filepath):
album = album.text album = album.text
if (lyric): if (lyric):
lyric = lyric.text lyric = lyric.text
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: else:
lyric = [None] lyric = [None]
else: else:
@ -182,6 +194,8 @@ def getAudioMeta(filepath):
lyric = filterLyricLine(f.read()) lyric = filterLyricLine(f.read())
if (not checkLyricValid(lyric)): if (not checkLyricValid(lyric)):
lyric = [None] lyric = [None]
else:
lyric = [lyric]
f.close() f.close()
else: else:
lyric = [None] lyric = [None]

View File

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