fix(file): 修复删除歌曲时的文件名问题并优化歌词显示

- 在删除歌曲时,先尝试停止播放并删除关联的歌词文件
- 优化文件名处理,避免特殊字符导致的文件名错误
- 更新歌词显示逻辑,修复歌词格式问题
- 版本号更新至 4.2.2
This commit is contained in:
2025-05-01 12:58:20 +08:00
parent 6b663a6ba9
commit a3c9a6261c

View File

@ -222,6 +222,7 @@ def download_music(song_name, choose):
music_url = resp.json()["music_url"] music_url = resp.json()["music_url"]
else: else:
lrc = "" lrc = ""
lrc = lrc.replace("\\n", "\n")
print("请求api:", url) print("请求api:", url)
response = requests.get(music_url, stream=True) response = requests.get(music_url, stream=True)
print("下载直链:", music_url) print("下载直链:", music_url)
@ -229,11 +230,12 @@ def download_music(song_name, choose):
if formated not in ["m4a", "mp3", "ogg", "flac"]: if formated not in ["m4a", "mp3", "ogg", "flac"]:
formated = "mp3" formated = "mp3"
filename_without_endswith = f"{singer} - {music_name}" filename_without_endswith = f"{singer} - {music_name}"
filename_without_endswith = filename_without_endswith.replace("\\", "#").replace("/", "#")
filename_without_endswith = filename_without_endswith.replace(":", "#").replace("*", "#")
filename_without_endswith = filename_without_endswith.replace("?", "#").replace("\"", "#")
filename_without_endswith = filename_without_endswith.replace("<", "#").replace(">", "#").replace("|", "#")
filename = f"{filename_without_endswith}.{formated}" filename = f"{filename_without_endswith}.{formated}"
filename = filename.replace("\\", "#").replace("/", "#")
filename = filename.replace(":", "#").replace("*", "#")
filename = filename.replace("?", "#").replace("\"", "#")
filename = filename.replace("<", "#").replace(">", "#").replace("|", "#")
temp_filename = f"{filename}.crdownload" temp_filename = f"{filename}.crdownload"
if path == "./music": if path == "./music":
@ -423,18 +425,29 @@ def delete():
file.endswith(('.mp3', '.flac', '.ogg', '.m4a'))] file.endswith(('.mp3', '.flac', '.ogg', '.m4a'))]
abs_path = path + "/" + music_dir0[listbox1.curselection()[0]] abs_path = path + "/" + music_dir0[listbox1.curselection()[0]]
abs_path_lrc = path + "/" + music_dir_without_endswith0[listbox1.curselection()[0]] + ".lrc" abs_path_lrc = path + "/" + music_dir_without_endswith0[listbox1.curselection()[0]] + ".lrc"
music_dir_without_endswith.remove(filtered_list[listbox1.curselection()[0]])
os.remove(abs_path) os.remove(abs_path)
try: try:
os.remove(abs_path_lrc) os.remove(abs_path_lrc)
except: except:
pass pass
music_dir_without_endswith.remove(filtered_list[listbox1.curselection()[0]])
music_dir.remove(music_dir[listbox1.curselection()[0]]) music_dir.remove(music_dir[listbox1.curselection()[0]])
listbox1.delete(listbox1.curselection()[0]) listbox1.delete(listbox1.curselection()[0])
except IndexError: except IndexError:
tkinter.messagebox.showwarning(title=lang.get(la, "mbox.title.delete_fail"), tkinter.messagebox.showwarning(title=lang.get(la, "mbox.title.delete_fail"),
message=lang.get(la, "mbox.text.delete_fail_no_target", )) message=lang.get(la, "mbox.text.delete_fail_no_target", ))
except PermissionError: except PermissionError:
try:
music_player.stop_music()
os.remove(abs_path)
try:
os.remove(abs_path_lrc)
except:
pass
music_dir_without_endswith.remove(filtered_list[listbox1.curselection()[0]])
music_dir.remove(music_dir[listbox1.curselection()[0]])
listbox1.delete(listbox1.curselection()[0])
except:
tkinter.messagebox.showerror(title=lang.get(la, "mbox.title.delete_fail"), tkinter.messagebox.showerror(title=lang.get(la, "mbox.title.delete_fail"),
message=lang.get(la, "mbox.text.delete_fail_no_permission", )) message=lang.get(la, "mbox.text.delete_fail_no_permission", ))
except FileNotFoundError: except FileNotFoundError:
@ -1310,7 +1323,7 @@ def search_local_song():
time.sleep(1) time.sleep(1)
version = "4.2.1" version = "4.2.2"
poem = "" poem = ""
appdata = os.getenv("APPDATA") appdata = os.getenv("APPDATA")
make_resource() make_resource()