failed_list.txt keep order remove duplication

This commit is contained in:
lededev
2021-10-17 21:21:12 +08:00
parent 189f4db616
commit b006aee34d

View File

@@ -252,14 +252,14 @@ def movie_lists(source_folder, regexstr):
failed_set = set() failed_set = set()
if (main_mode == 3 or soft_link) and not conf.ignore_failed_list(): if (main_mode == 3 or soft_link) and not conf.ignore_failed_list():
try: try:
with open(failed_list_txt_path, 'r', encoding='utf-8') as flt: flist = failed_list_txt_path.read_text(encoding='utf-8').splitlines()
flist = flt.read().splitlines()
failed_set = set(flist) failed_set = set(flist)
if len(flist) != len(failed_set): if len(flist) != len(failed_set): # 检查去重并写回但是不改变failed_list.txt内条目的先后次序重复的只保留最后的
with open(failed_list_txt_path, 'w', encoding='utf-8') as flt: fset = failed_set.copy()
wtlines = [line + '\n' for line in failed_set] for i in range(len(flist)-1, -1, -1):
wtlines.sort() fset.remove(flist[i]) if flist[i] in fset else flist.pop(i)
flt.writelines(wtlines) failed_list_txt_path.write_text('\n'.join(flist) + '\n', encoding='utf-8')
assert len(fset) == 0 and len(flist) == len(failed_set)
except: except:
pass pass
if not Path(source_folder).is_dir(): if not Path(source_folder).is_dir():