fix 实时软连接v1.9.8

新增模糊匹配交互命令
This commit is contained in:
thsrite
2024-07-18 15:54:51 +08:00
parent 0770e6fed2
commit 1f20f956a2
3 changed files with 53 additions and 21 deletions

View File

@@ -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

View File

@@ -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": "增强交互命令",

View File

@@ -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"
}
}
]