From df1ba462a28a8ca72d373db5b6b7721aa62235b4 Mon Sep 17 00:00:00 2001 From: thsrite Date: Thu, 27 Jun 2024 12:00:14 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=B6=E6=96=87=E4=BB=B6=E4=B8=8D=E5=AD=98=E5=9C=A8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- package.json | 3 ++- plugins/libraryduplicatecheck/__init__.py | 31 +++++++++++++---------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a3d6681..e950b80 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,4 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/ - CloudDrive2助手 v1.2 - 软连接重定向 v1.0 - 云盘同步删除 v1.2 -- 媒体库重复媒体检测 v1.3 \ No newline at end of file +- 媒体库重复媒体检测 v1.4 \ No newline at end of file diff --git a/package.json b/package.json index f8ab0ae..6d6580d 100644 --- a/package.json +++ b/package.json @@ -587,11 +587,12 @@ "name": "媒体库重复媒体检测", "description": "媒体库重复媒体检查,可选择保留规则保留其一。", "labels": "云盘,媒体库", - "version": "1.2", + "version": "1.4", "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/libraryduplicate.png", "author": "thsrite", "level": 2, "history": { + "v1.4": "修复删除时文件不存在bug", "v1.3": "各路径支持自定义保留规则", "v1.2": "支持通知推送", "v1.1": "支持自动刷新媒体库", diff --git a/plugins/libraryduplicatecheck/__init__.py b/plugins/libraryduplicatecheck/__init__.py index a6b9fc5..4b35d44 100644 --- a/plugins/libraryduplicatecheck/__init__.py +++ b/plugins/libraryduplicatecheck/__init__.py @@ -26,7 +26,7 @@ class LibraryDuplicateCheck(_PluginBase): # 插件图标 plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/libraryduplicate.png" # 插件版本 - plugin_version = "1.3" + plugin_version = "1.4" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -202,8 +202,8 @@ class LibraryDuplicateCheck(_PluginBase): for root, _, files in os.walk(directory): for file in files: # Check the file extension - if Path(file).suffix.lower() in [ext.strip() for ext in - self._rmt_mediaext.split(",")]: + if Path(file).exists() and Path(file).suffix.lower() in [ext.strip() for ext in + self._rmt_mediaext.split(",")]: video_name = Path(file).stem.split('-')[0].rstrip() logger.info(f'Scan file -> {file} -> {video_name}') video_files[video_name].append(os.path.join(root, file)) @@ -217,7 +217,10 @@ class LibraryDuplicateCheck(_PluginBase): duplicate_files += len(paths) logger.info(f"Duplicate video files for '{name}':") for path in paths: - logger.info(f" {path} 文件大小:{os.path.getsize(path)},创建时间:{os.path.getmtime(path)}") + if Path(path).exists(): + logger.info(f" {path} 文件大小:{os.path.getsize(path)},创建时间:{os.path.getmtime(path)}") + else: + logger.info(f" {path} 文件已被删除") if str(retain_type) != "仅检查": # Decide which file to keep based on criteria (e.g., file size or creation date) @@ -225,7 +228,7 @@ class LibraryDuplicateCheck(_PluginBase): logger.info(f"文件保留规则:{str(retain_type)} Keeping: {keep_path}") # Delete the other duplicate files (if needed) for path in paths: - if path != keep_path: + if Path(path).exists() and path != keep_path: cloud_file = os.readlink(path) Path(path).unlink() delete_duplicate_files += 1 @@ -233,12 +236,11 @@ class LibraryDuplicateCheck(_PluginBase): self.__rmtree(Path(path), "监控") # 同步删除软连接源目录 - if cloud_file and self._delete_softlink: - if Path(cloud_file).exists(): - Path(cloud_file).unlink() - delete_cloud_files += 1 - logger.info(f"云盘文件 {cloud_file} 已删除") - self.__rmtree(Path(cloud_file), "云盘") + if cloud_file and Path(cloud_file).exists() and self._delete_softlink: + Path(cloud_file).unlink() + delete_cloud_files += 1 + logger.info(f"云盘文件 {cloud_file} 已删除") + self.__rmtree(Path(cloud_file), "云盘") else: logger.info(f"'{name}' No Duplicate video files.") @@ -257,9 +259,10 @@ class LibraryDuplicateCheck(_PluginBase): # 父目录非根目录,才删除父目录 if not SystemUtils.exits_files(parent_path, [ext.strip() for ext in self._rmt_mediaext.split(",")]): - # 当前路径下没有媒体文件则删除 - shutil.rmtree(parent_path) - logger.warn(f"{file_type}目录 {parent_path} 已删除") + if parent_path.exists(): + # 当前路径下没有媒体文件则删除 + shutil.rmtree(parent_path) + logger.warn(f"{file_type}目录 {parent_path} 已删除") @staticmethod def __choose_file_to_keep(paths, retain_type):