From 3c85707569eee943e7b924dd69e274dd845b75f6 Mon Sep 17 00:00:00 2001 From: thsrite Date: Thu, 27 Jun 2024 10:42:59 +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=8Bv1.2=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=80=9A=E7=9F=A5=E6=8E=A8=E9=80=81?= 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 | 28 +++++++++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8523f5d..94d15ae 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.1 \ No newline at end of file +- 媒体库重复媒体检测 v1.2 \ No newline at end of file diff --git a/package.json b/package.json index a47913d..6fdeee2 100644 --- a/package.json +++ b/package.json @@ -587,11 +587,12 @@ "name": "媒体库重复媒体检测", "description": "媒体库重复媒体检查,可选择保留规则保留其一。", "labels": "媒体库", - "version": "1.1", + "version": "1.2", "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/libraryduplicate.png", "author": "thsrite", "level": 2, "history": { + "v1.2": "支持通知推送", "v1.1": "支持自动刷新媒体库", "v1.0": "媒体库重复媒体检查,可选择保留规则保留其一" } diff --git a/plugins/libraryduplicatecheck/__init__.py b/plugins/libraryduplicatecheck/__init__.py index b9a70d3..92781e9 100644 --- a/plugins/libraryduplicatecheck/__init__.py +++ b/plugins/libraryduplicatecheck/__init__.py @@ -12,7 +12,7 @@ from app.log import logger from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.triggers.cron import CronTrigger -from app.schemas.types import EventType +from app.schemas.types import EventType, NotificationType from app.utils.http import RequestUtils from app.utils.system import SystemUtils @@ -25,7 +25,7 @@ class LibraryDuplicateCheck(_PluginBase): # 插件图标 plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/libraryduplicate.png" # 插件版本 - plugin_version = "1.1" + plugin_version = "1.2" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -120,9 +120,13 @@ class LibraryDuplicateCheck(_PluginBase): logger.warning("媒体库重复媒体检测服务未配置路径") return + duplicate_files = 0 + delete_duplicate_files = 0 + delete_cloud_files = 0 + for path in self._paths.keys(): logger.info(f"开始检查路径:{path}") - self.__find_duplicate_videos(path) + self.__find_duplicate_videos(path, duplicate_files, delete_duplicate_files, delete_cloud_files) logger.info(f"路径 {path} 检查完毕") library_name = self._paths.get(path) @@ -146,6 +150,16 @@ class LibraryDuplicateCheck(_PluginBase): logger.error(f"媒体库:{library_name} 刷新失败") break + if self._notify: + self.post_message( + mtype=NotificationType.Plugin, + title="媒体库重复媒体检测", + text=f"本地重复文件: {duplicate_files}\n" + f"删除本地文件: {delete_duplicate_files}\n" + f"删除云盘文件: {delete_cloud_files}", + link=settings.MP_DOMAIN('#/history') + ) + def __refresh_emby_library_by_id(self, item_id: str) -> bool: """ 通知Emby刷新一个项目的媒体库 @@ -164,7 +178,7 @@ class LibraryDuplicateCheck(_PluginBase): return False return False - def __find_duplicate_videos(self, directory): + def __find_duplicate_videos(self, directory, duplicate_files, delete_duplicate_files, delete_cloud_files): """ 检查目录下视频文件是否有重复 """ @@ -181,11 +195,13 @@ class LibraryDuplicateCheck(_PluginBase): logger.info(f'Scan file -> {file} -> {video_name}') video_files[video_name].append(os.path.join(root, file)) - logger.info() + logger.info("") logger.info("================== RESULT ==================") + # Find and handle duplicate video files for name, paths in video_files.items(): if len(paths) > 1: + 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)}") @@ -199,6 +215,7 @@ class LibraryDuplicateCheck(_PluginBase): if path != keep_path: cloud_file = os.readlink(path) # Path(path).unlink() + delete_duplicate_files += 1 logger.info(f"Deleted Local file: {path}") self.__rmtree(Path(path), "监控") @@ -213,6 +230,7 @@ class LibraryDuplicateCheck(_PluginBase): files = cloud_file_path.parent.glob(f"{pattern}.*") for file in files: # Path(file).unlink() + delete_cloud_files += 1 logger.info(f"云盘文件 {file} 已删除") self.__rmtree(cloud_file_path, "云盘")