From f10025728b9553aa9079cbc962cd2a602a927cdb Mon Sep 17 00:00:00 2001 From: thsrite Date: Fri, 15 Nov 2024 10:39:27 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=9B=AE=E5=BD=95=E6=A0=91=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E7=BA=A7=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 3 ++- plugins.v2/cloudstrmcompanion/__init__.py | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/package.v2.json b/package.v2.json index 8bca34f..d3e15d1 100644 --- a/package.v2.json +++ b/package.v2.json @@ -401,11 +401,12 @@ "name": "云盘Strm助手", "description": "实时监控、定时全量增量生成strm文件。", "labels": "云盘", - "version": "1.0.8", + "version": "1.0.9", "icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/cloudcompanion.png", "author": "thsrite", "level": 1, "history": { + "v1.0.9": "目录树支持多级结构", "v1.0.8": "修复重建缓存不生效", "v1.0.7": "修复复制非媒体文件时父目录不存在", "v1.0.6": "支持[目录实时监控]插件联动", diff --git a/plugins.v2/cloudstrmcompanion/__init__.py b/plugins.v2/cloudstrmcompanion/__init__.py index 35b72a2..eaa3483 100644 --- a/plugins.v2/cloudstrmcompanion/__init__.py +++ b/plugins.v2/cloudstrmcompanion/__init__.py @@ -58,7 +58,7 @@ class CloudStrmCompanion(_PluginBase): # 插件图标 plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/cloudcompanion.png" # 插件版本 - plugin_version = "1.0.8" + plugin_version = "1.0.9" # 插件作者 plugin_author = "thsrite" # 作者主页 @@ -308,9 +308,9 @@ class CloudStrmCompanion(_PluginBase): if not tree_content: continue # 遍历云盘树形结构文件 - for cloud_file in self.parse_tree_structure(tree_content): + for cloud_file in self.parse_tree_structure(content=tree_content, dir_path=cloud_dir): try: - if Path(cloud_file).is_dir(): + if Path(str(cloud_file)).is_dir(): continue # 本地挂载路径 local_file = str(cloud_file).replace(cloud_dir, local_dir) @@ -544,24 +544,26 @@ class CloudStrmCompanion(_PluginBase): return None @staticmethod - def parse_tree_structure(content: str): + def parse_tree_structure(content: str, dir_path: str): """ 解析目录树内容并生成每个路径 """ tree_pattern = re_compile(r"^(?:\| )+\|-") - current_path = ["/"] # 初始化当前路径为根目录 + dir_path = Path(dir_path) + current_path = [str(dir_path.parent)] if dir_path.parent != Path("/") or (dir_path.parent == dir_path and ( + dir_path.is_absolute() or ':' in dir_path.name)) else ["/"] # 初始化当前路径为根目录 for line in content.splitlines(): # 匹配目录树的每一行 match = tree_pattern.match(line) - if not match or "根目录" in line: + if not match: continue # 跳过不符合格式的行 # 计算当前行的深度 level_indicator = match.group(0) depth = (len(level_indicator) // 2) - 1 - # 获取当前行的目录名称 - item_name = escape(line.strip()[len(level_indicator):]) + # 获取当前行的目录名称,去掉前面的 '| ' 或 '- ' + item_name = escape(line.strip()[len(level_indicator):].strip()) # 根据深度更新当前路径 if depth < len(current_path): @@ -570,7 +572,7 @@ class CloudStrmCompanion(_PluginBase): current_path.append(item_name) # 添加新的深度名称 # 生成并返回当前深度的完整路径 - yield join_path(*current_path[:depth + 1]) + yield join_path(*current_path[:depth + 1]).replace('\\', '/') @eventmanager.register(EventType.PluginAction) def remote_sync_one(self, event: Event = None):