From 4956aaa385a8740ece20a0f82530f8ba6947e021 Mon Sep 17 00:00:00 2001 From: 1826013250 <1826013250@qq.com> Date: Sun, 16 Apr 2023 14:00:41 +0800 Subject: [PATCH] Fix Load Error --- modules/functions/load_file_song.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/functions/load_file_song.py b/modules/functions/load_file_song.py index d4604dc..1b828c0 100644 --- a/modules/functions/load_file_song.py +++ b/modules/functions/load_file_song.py @@ -7,6 +7,7 @@ from multiprocessing import Process, Queue from queue import Empty from time import sleep +import mutagen.mp3 from progress.bar import Bar from Cryptodome.Cipher import AES from mutagen import File, flac @@ -19,7 +20,10 @@ from modules.utils.inputs import cinput, rinput def load_information_from_song(path) -> str | dict: """从音乐文件中的 Comment 字段获取 163 key 并解密返回歌曲信息""" - file = File(path) # 使用 mutagen 获取歌曲信息 + try: + file = File(path) # 使用 mutagen 获取歌曲信息 + except mutagen.mp3.HeaderNotFoundError: + return "not_a_music" if os.path.splitext(path)[-1] == ".mp3": # 当文件为 mp3 时使用 ID3 格式读取 if file.tags.get("COMM::XXX"): if file.tags["COMM::XXX"].text[0][:7] == "163 key": @@ -193,6 +197,9 @@ def get_lyric_from_folder(self): elif result == "not_a_normal_music": fails += 1 print(f"文件 \"{i}\" 内 163 key 不是一个普通音乐文件,这可能是一个电台曲目") + elif result == "not_a_music": + fails += 1 + print(f"文件 \"{i}\" 不是一个音乐文件,请检查该文件是否正常") else: musics.append({"id": result['musicId'], "name": result["musicName"], "artists": result["artist"]}) elif ext == ".ncm": # 对于 ncm 先加入到列表,等待解密