From 77f647e3b9c24b9dae6cce83fe87bb5ada6e2eee Mon Sep 17 00:00:00 2001 From: thsrite Date: Wed, 20 Nov 2024 16:05:36 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4strm?= =?UTF-8?q?=E5=90=8E=E5=88=A0=E9=99=A4=E6=9C=AC=E5=9C=B0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- plugins/cloudsyncdel/__init__.py | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 7e1df16..4d07171 100644 --- a/package.json +++ b/package.json @@ -631,12 +631,13 @@ "name": "云盘同步删除", "description": "媒体库删除软连接文件后,同步删除云盘文件。", "labels": "云盘", - "version": "1.5.6", + "version": "1.5.7", "icon": "clouddisk.png", "author": "thsrite", "level": 2, "v2": true, "history": { + "v1.5.7": "修复删除strm后删除本地文件", "v1.5.6": "修复媒体库路径映射", "v1.5.5": "兼容strm删除", "v1.5.4": "fix插件历史ui", diff --git a/plugins/cloudsyncdel/__init__.py b/plugins/cloudsyncdel/__init__.py index ea0d2ed..f098c5f 100644 --- a/plugins/cloudsyncdel/__init__.py +++ b/plugins/cloudsyncdel/__init__.py @@ -21,7 +21,7 @@ class CloudSyncDel(_PluginBase): # 插件图标 plugin_icon = "clouddisk.png" # 插件版本 - plugin_version = "1.5.6" + plugin_version = "1.5.7" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -101,6 +101,7 @@ class CloudSyncDel(_PluginBase): local_path = self.__get_path(self._local_paths, media_path) logger.info(f"获取到 {self._local_paths} 替换后本地文件路径 {local_path}") + is_local = False if Path(local_path).exists() and ( Path(local_path).is_dir() or (Path(local_path).is_file() and not Path(local_path).is_symlink())): if Path(local_path).is_dir(): @@ -117,6 +118,7 @@ class CloudSyncDel(_PluginBase): eventItem.episode_id = episode_num eventItem.item_isvirtual = "False" self.eventmanager.send_event(EventType.WebhookMessage, eventItem) + is_local = True else: # 检索相同目录下同名的媒体文件 pattern = Path(local_path).stem.replace('[', '?').replace(']', '?') @@ -126,15 +128,16 @@ class CloudSyncDel(_PluginBase): if not files: logger.info(f"未找到本地同名文件 {pattern},开始删除云盘") else: + is_local = True for file in files: Path(file).unlink() logger.info(f"本地文件 {file} 已删除") if Path(file).suffix in settings.RMT_MEDIAEXT: - logger.info(f"获取到本地路径 {local_path}, 通知媒体库同步删除插件删除") + logger.info(f"获取到本地路径 {file}, 通知媒体库同步删除插件删除") eventItem = schemas.WebhookEventInfo(event="media_del", channel="emby") eventItem.item_type = media_type eventItem.item_name = media_name - eventItem.item_path = local_path + eventItem.item_path = file eventItem.tmdb_id = tmdb_id eventItem.season_id = season_num eventItem.episode_id = episode_num @@ -147,6 +150,22 @@ class CloudSyncDel(_PluginBase): thumb_file.unlink() logger.info(f"本地文件 {thumb_file} 已删除") + # 删除空目录 + # 判断当前媒体父路径下是否有媒体文件,如有则无需遍历父级 + if not SystemUtils.exits_files(local_path.parent, settings.RMT_MEDIAEXT): + # 判断父目录是否为空, 为空则删除 + for parent_path in local_path.parents: + if str(parent_path.parent) != str(local_path.root): + # 父目录非根目录,才删除父目录 + if not SystemUtils.exits_files(parent_path, settings.RMT_MEDIAEXT): + # 当前路径下没有媒体文件则删除 + shutil.rmtree(parent_path) + logger.warn(f"本地目录 {parent_path} 已删除") + + # 本地文件不继续处理 + if is_local: + return + media_path = self.__get_path(self._paths, media_path) if not media_path: return