Skip to content

Commit

Permalink
fix: 修复LRC文件读取歌词
Browse files Browse the repository at this point in the history
  • Loading branch information
helloplhm-qwq committed Feb 4, 2024
1 parent a55da25 commit 35f1fe5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions common/localMusic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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]
Expand Down
1 change: 1 addition & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())):
Expand Down

0 comments on commit 35f1fe5

Please sign in to comment.