fix(NFLmusic):优化歌词时间戳格式转换与异常处理

- 新增正则表达式匹配并转换 [mm:ss] 时间戳为 [mm:ss.0] 格式
- 在下载酷狗歌词时增加时间戳标准化处理逻辑
- 打印原始歌词内容以便调试
- 修改异常捕获方式,明确打印异常类型和信息- 更新版本号从4.3.3 到4.3.4
This commit is contained in:
2025-10-03 17:07:50 +08:00
parent 12a8b3714c
commit bbe244e125

View File

@ -204,6 +204,20 @@ def download_music(song_name, choose):
resp.close() resp.close()
try: try:
lrc = resp.json()["data"]["lyric"] lrc = resp.json()["data"]["lyric"]
print(lrc)
# 正则表达式匹配 [mm:ss]
def convert_timestamp(match):
mm_ss = match.group(1)
minutes, seconds = mm_ss.split(':')
# 转换为浮点秒数并保留一位小数(虽然这里是整数)
total_seconds = int(minutes) * 60 + int(seconds)
# 格式化回 mm:ss.s 形式
new_minutes = total_seconds // 60
new_seconds = total_seconds % 60
return f"[{new_minutes:02d}:{new_seconds:02d}.0]"
# 替换所有 [mm:ss] 为 [mm:ss.0]
lrc = re.sub(r'\[(\d{2}:\d{2})\]', convert_timestamp, lrc)
except Exception as e: except Exception as e:
print(f"download_kg_lrc: {e}") print(f"download_kg_lrc: {e}")
lrc = "" lrc = ""
@ -483,8 +497,8 @@ def playsound(*event):
playmusic(abs_path) playmusic(abs_path)
try: try:
lyric = lyrics.load_lyrics(f"{path}/{music_file_without_endswith}.lrc") lyric = lyrics.load_lyrics(f"{path}/{music_file_without_endswith}.lrc")
except: except Exception as e:
pass print(type(e), e)
def playmusic(music_path): def playmusic(music_path):
@ -1314,7 +1328,7 @@ def search_local_song():
time.sleep(1) time.sleep(1)
version = "4.3.3" version = "4.3.4"
poem = "" poem = ""
appdata = os.getenv("APPDATA") appdata = os.getenv("APPDATA")
make_resource() make_resource()