From 35f1fe513a98b617da5d6676562f6757b6484c03 Mon Sep 17 00:00:00 2001 From: helloplhm-qwq Date: Sun, 4 Feb 2024 16:17:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DLRC=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=AD=8C=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/localMusic.py | 20 +++++++++++++++++--- main.py | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/common/localMusic.py b/common/localMusic.py index 4022455..b91ac56 100644 --- a/common/localMusic.py +++ b/common/localMusic.py @@ -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] diff --git a/main.py b/main.py index 24cb3e9..71436a9 100644 --- a/main.py +++ b/main.py @@ -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())):