failed_list.txt keep order remove duplication
This commit is contained in:
@@ -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): # 检查去重并写回,但是不改变failed_list.txt内条目的先后次序,重复的只保留最后的
|
||||||
if len(flist) != len(failed_set):
|
fset = failed_set.copy()
|
||||||
with open(failed_list_txt_path, 'w', encoding='utf-8') as flt:
|
for i in range(len(flist)-1, -1, -1):
|
||||||
wtlines = [line + '\n' for line in failed_set]
|
fset.remove(flist[i]) if flist[i] in fset else flist.pop(i)
|
||||||
wtlines.sort()
|
failed_list_txt_path.write_text('\n'.join(flist) + '\n', encoding='utf-8')
|
||||||
flt.writelines(wtlines)
|
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():
|
||||||
|
|||||||
Reference in New Issue
Block a user