mirror of
https://github.com/thsrite/MoviePilot-Plugins.git
synced 2026-03-27 10:05:57 +00:00
fix 目录树支持多级结构
This commit is contained in:
@@ -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": "支持[目录实时监控]插件联动",
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user