fix(local_song): 修复删除歌曲后搜索结果异常的问题
-修复删除歌曲后,搜索结果列表显示异常的问题 - 优化搜索歌曲逻辑,确保删除歌曲后搜索结果能够正确更新 -调整变量初始化顺序,提高代码可读性和维护性
This commit is contained in:
24
NFLmusic.py
24
NFLmusic.py
@ -326,22 +326,32 @@ def refresh():
|
||||
music_dir = [file for file in os.listdir(path) if file.endswith(('.mp3', '.flac', '.ogg', '.m4a'))]
|
||||
if var7.get() in ["", lang.get(la, "ui.download.entry.song_name")]:
|
||||
for musics in music_dir_without_endswith:
|
||||
listbox1.insert("end", musics)
|
||||
listbox1.insert(END, musics)
|
||||
else:
|
||||
for musics in music_dir_without_endswith:
|
||||
if search_words in musics:
|
||||
listbox1.insert("end", musics)
|
||||
listbox1.insert(END, musics)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def delete():
|
||||
global music_dir, listbox1, music_dir_without_endswith, filtered_list
|
||||
global listbox1, filtered_list, music_dir, music_dir_without_endswith
|
||||
try:
|
||||
if tkinter.messagebox.askokcancel(lang.get(la, "mbox.title.delete"), lang.get(la, "mbox.text.delete", )):
|
||||
abs_path = path + "/" + music_dir[listbox1.curselection()[0]]
|
||||
abs_path_lrc = path + "/" + music_dir_without_endswith[listbox1.curselection()[0]] + ".lrc"
|
||||
music_dir_without_endswith.remove(filtered_list[listbox1.curselection()[0] - 1])
|
||||
if var7.get() not in ["", lang.get(la, "ui.download.entry.song_name")]:
|
||||
music_dir_filtered = []
|
||||
for file in music_dir:
|
||||
if search_words in os.path.splitext(file)[0]:
|
||||
music_dir_filtered.append(file)
|
||||
music_dir0 = music_dir_filtered
|
||||
music_dir_without_endswith0 = [os.path.splitext(file)[0] for file in music_dir if
|
||||
file.endswith(('.mp3', '.flac', '.ogg', '.m4a'))]
|
||||
abs_path = path + "/" + music_dir0[listbox1.curselection()[0]]
|
||||
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)
|
||||
try:
|
||||
os.remove(abs_path_lrc)
|
||||
@ -1207,7 +1217,7 @@ def download_version():
|
||||
|
||||
|
||||
def search_local_song():
|
||||
global search_words, filtered_list
|
||||
global search_words, filtered_list, music_dir_without_endswith
|
||||
while True:
|
||||
if focused:
|
||||
former_words = var7.get()
|
||||
@ -1220,7 +1230,7 @@ def search_local_song():
|
||||
listbox1.unbind("<Double-1>")
|
||||
else:
|
||||
listbox1.bind("<Double-1>", playsound)
|
||||
print(filtered_list)
|
||||
print(music_dir_without_endswith)
|
||||
listbox1.delete(0, END)
|
||||
for song in filtered_list:
|
||||
listbox1.insert(END, song)
|
||||
@ -1228,7 +1238,7 @@ def search_local_song():
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
version = "4.1.5"
|
||||
version = "4.1.6"
|
||||
poem = ""
|
||||
appdata = os.getenv("APPDATA")
|
||||
make_resource()
|
||||
|
Reference in New Issue
Block a user