From 1f20f956a2d4be135cd4db7077fc420b12677b9f Mon Sep 17 00:00:00 2001 From: thsrite Date: Thu, 18 Jul 2024 15:54:51 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=AE=9E=E6=97=B6=E8=BD=AF=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5v1.9.8=20=E6=96=B0=E5=A2=9E=E6=A8=A1=E7=B3=8A=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E4=BA=A4=E4=BA=92=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- package.json | 3 +- plugins/filesoftlink/__init__.py | 69 +++++++++++++++++++++++--------- 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index e846a2f..680c914 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ MoviePilot三方插件市场:https://github.com/thsrite/MoviePilot-Plugins/ - [自定义命令 v1.7](docs%2FCustomCommand.md) - docker自定义任务 v1.3 - 插件彻底卸载 v1.0 -- 实时软连接 v1.9.7 +- 实时软连接 v1.9.8 - 订阅规则自动填充 v2.7 - Emby元数据刷新 v1.3 - Emby媒体标签 v1.2 diff --git a/package.json b/package.json index db487d6..59a4502 100644 --- a/package.json +++ b/package.json @@ -392,11 +392,12 @@ "name": "实时软连接", "description": "监控目录文件变化,媒体文件软连接,其他文件可选复制。", "labels": "文件管理", - "version": "1.9.7", + "version": "1.9.8", "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/softlink.png", "author": "thsrite", "level": 1, "history": { + "v1.9.8": "新增模糊匹配交互命令", "v1.9.7": "接收云盘实时监控处理单文件", "v1.9.6": "优化log", "v1.9.5": "增强交互命令", diff --git a/plugins/filesoftlink/__init__.py b/plugins/filesoftlink/__init__.py index c3e14de..3c80555 100644 --- a/plugins/filesoftlink/__init__.py +++ b/plugins/filesoftlink/__init__.py @@ -52,7 +52,7 @@ class FileSoftLink(_PluginBase): # 插件图标 plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/softlink.png" # 插件版本 - plugin_version = "1.9.7" + plugin_version = "1.9.8" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -284,7 +284,8 @@ class FileSoftLink(_PluginBase): def remote_sync_one(self, event: Event = None): if event: event_data = event.event_data - if not event_data or event_data.get("action") != "softlink_one": + if not event_data or ( + event_data.get("action") != "softlink_one" and event_data.get("action") != "softlink_all"): return args = event_data.get("args") if not args: @@ -306,23 +307,27 @@ class FileSoftLink(_PluginBase): if mon_category and str(category) in mon_category: parent_path = os.path.join(mon_path, category) logger.info(f"获取到 {category} {args} 对应的监控目录 {parent_path}") - for root, dirs, files in os.walk(parent_path): - for dir_name in dirs: - src_path = os.path.join(root, dir_name) - # 定向上级文件夹 - src_name = Path(src_path).name - if str(args) in str(src_name): - logger.info(f"开始定向处理文件夹 ...{src_path}") - for sroot, sdirs, sfiles in os.walk(src_path): - for file_name in sdirs + sfiles: - src_file = os.path.join(sroot, file_name) - if Path(src_file).is_file(): - self.__handle_file(event_path=str(src_file), mon_path=mon_path) - if event.event_data.get("user"): - self.post_message(channel=event.event_data.get("channel"), - title=f"{all_args} 软连接完成!", - userid=event.event_data.get("user")) - return + target_paths = self.__find_related_paths(os.path.join(str(parent_path), args)) + if not target_paths: + logger.error(f"未查找到 {category} {args} 对应的具体目录") + return + + for target_path in target_paths: + logger.info(f"开始定向处理文件夹 ...{target_path}") + for sroot, sdirs, sfiles in os.walk(target_path): + for file_name in sdirs + sfiles: + src_file = os.path.join(sroot, file_name) + if Path(src_file).is_file(): + self.__handle_file(event_path=str(src_file), mon_path=mon_path) + + if event.event_data.get("user"): + self.post_message(channel=event.event_data.get("channel"), + title=f"{target_path} 软连接完成!", + userid=event.event_data.get("user")) + + if event_data and event_data.get("action") == "softlink_one": + return + return else: # 遍历所有监控目录 @@ -377,6 +382,23 @@ class FileSoftLink(_PluginBase): title=f"{all_args} 未检索到,请检查输入是否正确!", userid=event.event_data.get("user")) + @staticmethod + def __find_related_paths(base_path): + related_paths = [] + base_dir = os.path.dirname(base_path) + base_name = os.path.basename(base_path) + + for entry in os.listdir(base_dir): + if entry.startswith(base_name): + full_path = os.path.join(base_dir, entry) + if os.path.isdir(full_path): + related_paths.append(full_path) + + # 按照修改时间倒序排列 + related_paths.sort(key=lambda path: os.path.getmtime(path), reverse=True) + + return related_paths + def sync_all(self): """ 立即运行一次,全量同步目录中所有文件 @@ -518,6 +540,15 @@ class FileSoftLink(_PluginBase): "data": { "action": "softlink_one" } + }, + { + "cmd": "/softall", + "event": EventType.PluginAction, + "desc": "定向软连接处理", + "category": "", + "data": { + "action": "softlink_all" + } } ]