From bf5bd5d4440bf3be61a9aedba36b9ac35f344351 Mon Sep 17 00:00:00 2001 From: lededev Date: Sun, 26 Sep 2021 06:35:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E9=87=8F=E6=95=B4=E7=90=86=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E9=80=82=E7=94=A8=E4=BA=8E=E6=89=80=E6=9C=89?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AV_Data_Capture.py | 40 ++++++++++++++++++++++++++++++---------- config.ini | 14 ++++++-------- config.py | 31 ++++++++++++------------------- core.py | 5 ++--- 4 files changed, 50 insertions(+), 40 deletions(-) diff --git a/AV_Data_Capture.py b/AV_Data_Capture.py index 4fbf25e..715ddf2 100755 --- a/AV_Data_Capture.py +++ b/AV_Data_Capture.py @@ -131,6 +131,8 @@ def movie_lists(root, conf): escape_folder = re.split("[,,]", conf.escape_folder()) failed_folder = conf.failed_folder() main_mode = conf.main_mode() + debug = conf.debug() + nfo_skip_days = conf.nfo_skip_days() total = [] file_type = conf.media_type().upper().split(",") trailerRE = re.compile(r'-trailer\.', re.IGNORECASE) @@ -149,17 +151,36 @@ def movie_lists(root, conf): continue absf = os.path.abspath(full_name) if absf in failed_list: - if conf.debug(): + if debug: print('[!]Skip failed file:', absf) continue - if main_mode == 3 and conf.mode3_nfo_skip_days() > 0: + if main_mode == 3 and nfo_skip_days > 0: nfo = Path(absf).with_suffix('.nfo') - if file_modification_days(nfo) <= conf.mode3_nfo_skip_days(): + if file_modification_days(nfo) <= nfo_skip_days: continue if (main_mode == 3 or not is_link(absf)) and not trailerRE.search(f): total.append(absf) except: pass + if nfo_skip_days <= 0 or not conf.soft_link(): + return total + # 软连接方式,已经成功削刮的也需要从成功目录中检查.nfo更新天数,跳过N天内更新过的 + skip_numbers = set() + success_folder = conf.success_folder() + for current_dir, subdirs, files in os.walk(success_folder, topdown=False): + for f in files: + if os.path.splitext(f)[1].upper() in file_type: + nfo_file = os.path.join(current_dir, str(Path(f).with_suffix('.nfo'))) + if file_modification_days(nfo_file) <= nfo_skip_days: + file_name = os.path.basename(f) + number = get_number(False, file_name) + if number: + skip_numbers.add(number.upper()) + for f in total: + file_name = os.path.basename(f) + n_number = get_number(False, file_name) + if n_number and n_number.upper() in skip_numbers: + total.pop(total.index(f)) return total @@ -295,22 +316,21 @@ if __name__ == '__main__': count_all = str(len(movie_list)) print('[+]Find', count_all, 'movies') main_mode = conf.main_mode() - stop_count = conf.mode3_stop_counter() + stop_count = conf.stop_counter() if stop_count<1: stop_count = 999999 - elif main_mode == 3: + else: count_all = str(min(len(movie_list), stop_count)) + if main_mode == 3: print( -f'[!]运行模式:**维护模式**,本程序将在处理{count_all}个视频文件后停止,如需后台执行自动退出请结合 -a 参数。' - ) - +f'[!]运行模式:**维护模式**,本程序将在处理{count_all}个视频文件后停止,如需后台执行自动退出请结合 -a 参数。') for movie_path in movie_list: # 遍历电影列表 交给core处理 count = count + 1 percentage = str(count / int(count_all) * 100)[:4] + '%' print('[!] - ' + percentage + ' [' + str(count) + '/' + count_all + '] -') create_data_and_move(movie_path, conf, conf.debug()) - if main_mode == 3 and count >= stop_count: - print("[!]Mode 3 stop counter triggered!") + if count >= stop_count: + print("[!]Stop counter triggered!") break if conf.del_empty_folder(): diff --git a/config.ini b/config.ini index d384bc4..2d655d5 100755 --- a/config.ini +++ b/config.ini @@ -10,6 +10,12 @@ multi_threading=1 ;actor_gender value: female(♀) or male(♂) or both(♀ ♂) or all(♂ ♀ ⚧) actor_gender=female del_empty_folder=1 +; 跳过最近(默认:30)天新修改过的.NFO,可避免整理模式(main_mode=3)和软连接(soft_link=0)时 +; 反复刮削靠前的视频文件,0为处理所有视频文件 +nfo_skip_days=30 +; 处理完多少个视频文件后停止,0为处理所有视频文件 +stop_counter=0 +; 以上两个参数配合使用可以以多次少量的方式刮削或整理数千个文件而不触发翻译或元数据站封禁 [proxy] ;proxytype: http or socks5 or socks5h switch: 0 1 @@ -75,11 +81,3 @@ water=2 switch=0 extrafanart_folder=extrafanart -; 整理模式 ([common] main_mode=3) -[main_mode_3] -; 整理时跳过最近(默认:30)天新修改过的.NFO,可避免反复整理靠前的文件,0为总是整理全部文件 -nfo_skip_days=30 -; 整理文件时达到指定个数即停止,配合google free翻译使用时,避免触发翻译次数上限导致的翻译失败,0为不限制 -mode3_stop_counter=0 -; 以上两个参数配合使用,可以用于定时执行的计划任务,例如将数千个视频文件的元数据在几周内分批更新 -; 程序启动参数'-o 日志目录'则可生成日志,检查几周内日志可找出失败文件手工处理 diff --git a/config.py b/config.py index 76ffcbd..274b90c 100644 --- a/config.py +++ b/config.py @@ -54,6 +54,16 @@ class Config: return self.conf.getboolean("common", "multi_threading") def del_empty_folder(self) -> bool: return self.conf.getboolean("common", "del_empty_folder") + def nfo_skip_days(self) -> int: + try: + return self.conf.getint("common", "nfo_skip_days") + except: + return 30 + def stop_counter(self) -> int: + try: + return self.conf.getint("common", "stop_counter") + except: + return 0 def is_transalte(self) -> bool: return self.conf.getboolean("transalte", "switch") def is_trailer(self) -> bool: @@ -149,18 +159,6 @@ class Config: def debug(self) -> bool: return self.conf.getboolean("debug_mode", "switch") - def mode3_nfo_skip_days(self) -> int: - try: - return self.conf.getint("main_mode_3", "nfo_skip_days") - except: - return 30 - - def mode3_stop_counter(self) -> int: - try: - return self.conf.getint("main_mode_3", "mode3_stop_counter") - except: - return 0 - @staticmethod def _exit(sec: str) -> None: print("[-] Read config error! Please check the {} section in config.ini", sec) @@ -183,6 +181,8 @@ class Config: # actor_gender value: female or male or both or all(含人妖) conf.set(sec1, "actor_gender", "female") conf.set(sec1, "del_empty_folder", "1") + conf.set(sec1, "nfo_skip_days", 30) + conf.set(sec1, "stop_counter", 0) sec2 = "proxy" conf.add_section(sec2) @@ -248,16 +248,9 @@ class Config: conf.set(sec13, "switch", 1) conf.set(sec13, "extrafanart_folder", "extrafanart") - sec14 = "main_mode_3" - conf.add_section(sec14) - conf.set(sec14, "nfo_skip_days", 30) - conf.set(sec14, "mode3_stop_counter", 0) - return conf - - class IniProxy(): """ Proxy Config from .ini """ diff --git a/core.py b/core.py index ea92cb5..4951fab 100755 --- a/core.py +++ b/core.py @@ -28,9 +28,8 @@ def moveFailedFolder(filepath, conf): # 模式3或软连接,改为维护一个失败列表,启动扫描时加载用于排除该路径,以免反复处理 # 原先的创建软连接到失败目录,并不直观,不方便找到失败文件位置,不如直接记录该文件路径 if conf.main_mode() == 3 or soft_link: - with open(os.path.join(failed_folder, 'failed_list.txt'), 'a', encoding='utf-8') as m3f: - m3f.write(f'{filepath}\n') - m3f.close() + open(os.path.join(failed_folder, 'failed_list.txt'), 'a', encoding='utf-8' + ).write(f'{filepath}\n').close() print('[-]Add to failed list file') elif conf.failed_move() and not soft_link: file_name = os.path.basename(filepath)