From 601e22fbabb8e7f04f8ec6eab488e803753b19e0 Mon Sep 17 00:00:00 2001 From: thsrite Date: Thu, 27 Jun 2024 11:29:09 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E5=AA=92=E4=BD=93=E5=BA=93=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=AA=92=E4=BD=93=E6=A3=80=E6=B5=8B=20v1.3=20?= =?UTF-8?q?=E5=90=84=E8=B7=AF=E5=BE=84=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E4=BF=9D=E7=95=99=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- package.json | 1 + plugins/libraryduplicatecheck/__init__.py | 31 ++++++++++++++++------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 94d15ae..a3d6681 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.2 \ No newline at end of file +- 媒体库重复媒体检测 v1.3 \ No newline at end of file diff --git a/package.json b/package.json index 13328a6..f8ab0ae 100644 --- a/package.json +++ b/package.json @@ -592,6 +592,7 @@ "author": "thsrite", "level": 2, "history": { + "v1.3": "各路径支持自定义保留规则", "v1.2": "支持通知推送", "v1.1": "支持自动刷新媒体库", "v1.0": "媒体库重复媒体检查,可选择保留规则保留其一" diff --git a/plugins/libraryduplicatecheck/__init__.py b/plugins/libraryduplicatecheck/__init__.py index 668386f..4f1fb76 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.2" + plugin_version = "1.3" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -42,6 +42,7 @@ class LibraryDuplicateCheck(_PluginBase): _enabled = False # 任务执行间隔 _paths = {} + _path_type = {} _notify = False _delete_softlink = False _cron = None @@ -75,6 +76,12 @@ class LibraryDuplicateCheck(_PluginBase): if config.get("path"): for path in str(config.get("path")).split("\n"): logger.info(f"添加媒体库路径:{path}") + + retain_type = self._retain_type + if path.count("$") == 1: + retain_type = path.split("$")[1] + path = path.split("$")[0] + if path.count("#") == 1: library_name = path.split("#")[1] path = path.split("#")[0] @@ -82,6 +89,8 @@ class LibraryDuplicateCheck(_PluginBase): else: self._paths[path] = None + self._path_type[path] = retain_type + if self._enabled or self._onlyonce: # 定时服务 self._scheduler = BackgroundScheduler(timezone=settings.TZ) @@ -125,8 +134,10 @@ class LibraryDuplicateCheck(_PluginBase): msg = "" for path in self._paths.keys(): - logger.info(f"开始检查路径:{path}") - duplicate_files, delete_duplicate_files, delete_cloud_files = self.__find_duplicate_videos(path) + _retain_type = self._path_type.get(path) + logger.info(f"开始检查路径:{path} {_retain_type}") + duplicate_files, delete_duplicate_files, delete_cloud_files = self.__find_duplicate_videos(path, + _retain_type) logger.info(f"路径 {path} 检查完毕") library_name = self._paths.get(path) @@ -146,7 +157,7 @@ class LibraryDuplicateCheck(_PluginBase): self.__refresh_emby_library_by_id(library.id) break msg += (f"{path}{'#' + library_name if library_name else ''} 检查完成\n" - f"文件保留规则: {self._retain_type}\n" + f"文件保留规则: {_retain_type}\n" f"本地重复文件: {duplicate_files}\n" f"删除本地文件: {delete_duplicate_files}\n" f"删除云盘文件: {delete_cloud_files}\n") @@ -177,7 +188,7 @@ class LibraryDuplicateCheck(_PluginBase): return False return False - def __find_duplicate_videos(self, directory): + def __find_duplicate_videos(self, directory, retain_type): """ 检查目录下视频文件是否有重复 """ @@ -209,10 +220,10 @@ class LibraryDuplicateCheck(_PluginBase): for path in paths: logger.info(f" {path} 文件大小:{os.path.getsize(path)},创建时间:{os.path.getmtime(path)}") - if str(self._retain_type) != "仅检查": + if str(retain_type) != "仅检查": # Decide which file to keep based on criteria (e.g., file size or creation date) - keep_path = self.__choose_file_to_keep(paths, self._retain_type) - logger.info(f"文件保留规则:{str(self._retain_type)} Keeping: {keep_path}") + keep_path = self.__choose_file_to_keep(paths, retain_type) + logger.info(f"文件保留规则:{str(retain_type)} Keeping: {keep_path}") # Delete the other duplicate files (if needed) for path in paths: if path != keep_path: @@ -454,7 +465,9 @@ class LibraryDuplicateCheck(_PluginBase): 'label': '检查路径', 'rows': 2, 'placeholder': "检查的媒体路径\n" - "检查的媒体路径#媒体库名称" + "检查的媒体路径$保留规则\n" + "检查的媒体路径#媒体库名称\n" + "检查的媒体路径#媒体库名称$保留规则\n" } }