From e8b2a3ab8f23583e3e7cacdaa290ec85faeb647d Mon Sep 17 00:00:00 2001 From: thsrite Date: Fri, 22 Nov 2024 14:25:23 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=88=A0=E9=99=A4strm=E6=96=87=E4=BB=B6=E5=A4=B9=E7=9A=84?= =?UTF-8?q?=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- plugins/cloudsyncdel/__init__.py | 93 ++++++++++++++++++-------------- 2 files changed, 56 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index bd149dd..cd42624 100644 --- a/package.json +++ b/package.json @@ -631,12 +631,13 @@ "name": "云盘同步删除", "description": "媒体库删除软连接文件后,同步删除云盘文件。", "labels": "云盘", - "version": "1.5.9", + "version": "1.5.10", "icon": "clouddisk.png", "author": "thsrite", "level": 2, "v2": true, "history": { + "v1.5.10": "修复直接删除strm文件夹的场景", "v1.5.9": "修复主程序修改事件任务后,同步删除未收到通知的问题", "v1.5.8": "修复删除strm后删除本地文件", "v1.5.6": "修复媒体库路径映射", diff --git a/plugins/cloudsyncdel/__init__.py b/plugins/cloudsyncdel/__init__.py index a47ebb2..d2926d1 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.9" + plugin_version = "1.5.10" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -121,47 +121,62 @@ class CloudSyncDel(_PluginBase): is_local = True else: if Path(local_path).parent.exists(): - # 检索相同目录下同名的媒体文件 - pattern = Path(local_path).stem.replace('[', '?').replace(']', '?') - logger.info(f"开始筛选 {Path(local_path).parent} 下同名文件 {pattern}") - files = Path(local_path).parent.glob(f"{pattern}.*") - - if not files: - logger.info(f"未找到本地同名文件 {pattern},开始删除云盘") + if Path(local_path).is_dir() and Path(local_path).exists(): + shutil.rmtree(local_path) + logger.info(f"本地目录 {local_path} 已删除") + logger.info(f"获取到本地路径 {local_path}, 通知媒体库同步删除插件删除") + self.eventmanager.send_event(EventType.PluginAction, { + 'media_type': media_type, + 'media_name': media_name, + 'media_path': local_path, + 'tmdb_id': tmdb_id, + 'season_num': season_num, + 'episode_num': episode_num, + 'action': 'media_sync_del' + }) else: - for file in files: - is_local = True - Path(file).unlink() - logger.info(f"本地文件 {file} 已删除") - if Path(file).suffix in settings.RMT_MEDIAEXT: - logger.info(f"获取到本地路径 {file}, 通知媒体库同步删除插件删除") - self.eventmanager.send_event(EventType.PluginAction, { - 'media_type': media_type, - 'media_name': media_name, - 'media_path': str(file), - 'tmdb_id': tmdb_id, - 'season_num': season_num, - 'episode_num': episode_num, - 'action': 'media_sync_del' - }) + if Path(local_path).is_file(): + # 检索相同目录下同名的媒体文件 + pattern = Path(local_path).stem.replace('[', '?').replace(']', '?') + logger.info(f"开始筛选 {Path(local_path).parent} 下同名文件 {pattern}") + files = Path(local_path).parent.glob(f"{pattern}.*") - # 删除thumb图片 - thumb_file = Path(local_path).parent / (Path(local_path).stem + "-thumb.jpg") - if thumb_file.exists(): - thumb_file.unlink() - logger.info(f"本地文件 {thumb_file} 已删除") + if not files: + logger.info(f"未找到本地同名文件 {pattern},开始删除云盘") + else: + for file in files: + is_local = True + Path(file).unlink() + logger.info(f"本地文件 {file} 已删除") + if Path(file).suffix in settings.RMT_MEDIAEXT: + logger.info(f"获取到本地路径 {file}, 通知媒体库同步删除插件删除") + self.eventmanager.send_event(EventType.PluginAction, { + 'media_type': media_type, + 'media_name': media_name, + 'media_path': str(file), + 'tmdb_id': tmdb_id, + 'season_num': season_num, + 'episode_num': episode_num, + 'action': 'media_sync_del' + }) - # 删除空目录 - # 判断当前媒体父路径下是否有媒体文件,如有则无需遍历父级 - 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} 已删除") + # 删除thumb图片 + thumb_file = Path(local_path).parent / (Path(local_path).stem + "-thumb.jpg") + if thumb_file.exists(): + 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: