From 41d214f391baae4e27daff9db115da045cea0445 Mon Sep 17 00:00:00 2001 From: lededev Date: Sun, 24 Apr 2022 00:54:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=89=E9=A1=B9=E5=85=BC?= =?UTF-8?q?=E5=AE=B9Jellyfin=E5=B0=81=E9=9D=A2=E5=9B=BE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.ini | 3 +++ config.py | 3 +++ core.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/config.ini b/config.ini index c17acc7..cc9c127 100755 --- a/config.ini +++ b/config.ini @@ -128,3 +128,6 @@ locations_model=hog uncensored_only=1 aways_imagecut=0 aspect_ratio=2.12 + +[jellyfin] +multi_part_fanart=0 diff --git a/config.py b/config.py index 783c2fe..2cd4015 100644 --- a/config.py +++ b/config.py @@ -394,6 +394,9 @@ class Config: def face_aspect_ratio(self) -> float: return self.conf.getfloat("face", "aspect_ratio", fallback=2.12) + def jellyfin_multi_part_fanart(self) -> bool: + return self.conf.getboolean("jellyfin", "multi_part_fanart", fallback=False) + @staticmethod def _exit(sec: str) -> None: print("[-] Read config error! Please check the {} section in config.ini", sec) diff --git a/core.py b/core.py index 7b493cf..da8b6c9 100644 --- a/core.py +++ b/core.py @@ -614,6 +614,40 @@ def paste_file_to_folder_mode2(filepath, path, multi_part, number, part, leak_wo return +def linkImage(path, number, part, leak_word, c_word, hack_word, ext): + """ + 首先尝试为图片建立符合Jellyfin封面图文件名规则的硬连接以节省磁盘空间 + 如果目标目录无法建立硬链接则将图片复制一份成为常规文件 + 常规文件日期已经存在时,若修改日期比源文件更旧,则将被新的覆盖,否则忽略 + """ + if not all(len(v) for v in (path, number, part, ext)): + return + covers = ("-fanart", "-poster", "-thumb") + normal_prefix = f"{number}{leak_word}{c_word}{hack_word}" + multi_prefix = f"{number}{part}{leak_word}{c_word}{hack_word}" + normal_pathes = (Path(path) / f"{normal_prefix}{c}{ext}" for c in covers) + multi_pathes = (Path(path) / f"{multi_prefix}{c}{ext}" for c in covers) + for normal_path, multi_path in zip(normal_pathes, multi_pathes): + if not normal_path.is_file(): + continue + mkLink = False + if not multi_path.exists(): + mkLink = True + elif multi_path.is_file(): + if multi_path.stat().st_nlink > 1: + continue + elif normal_path.stat().st_mtime <= multi_path.stat().st_mtime: + continue + mkLink = True + multi_path.unlink(missing_ok=True) + if not mkLink: + continue + try: + os.link(str(normal_path), str(multi_path), follow_symlinks=False) + except: + shutil.copyfile(str(normal_path), str(multi_path)) + + def debug_print(data: json): try: print("[+] ------- DEBUG INFO -------") @@ -791,6 +825,10 @@ def core_main(movie_path, number_th, oCC): if conf.is_watermark(): add_mark(os.path.join(path,poster_path), os.path.join(path,thumb_path), cn_sub, leak, uncensored, hack) + # 兼容Jellyfin封面图文件名规则 + if multi_part and conf.jellyfin_multi_part_fanart(): + linkImage(path, number_th, part, leak_word, c_word, hack_word, ext) + # 移动电影 paste_file_to_folder(movie_path, path, multi_part, number, part, leak_word, c_word, hack_word) @@ -834,6 +872,10 @@ def core_main(movie_path, number_th, oCC): if conf.is_watermark(): add_mark(os.path.join(path,poster_path), os.path.join(path,thumb_path), cn_sub, leak, uncensored, hack) + # 兼容Jellyfin封面图文件名规则 + if multi_part and conf.jellyfin_multi_part_fanart(): + linkImage(path, number_th, part, leak_word, c_word, hack_word, ext) + # 最后输出.nfo元数据文件,以完成.nfo文件创建作为任务成功标志 print_files(path, leak_word, c_word, json_data.get('naming_rule'), part, cn_sub, json_data, movie_path, tag, json_data.get('actor_list'), liuchu, uncensored, hack_word,fanart_path,poster_path,thumb_path)