This commit is contained in:
thsrite
2024-07-25 19:48:11 +08:00
parent aa5a5b598b
commit 5bb86a2320
3 changed files with 55 additions and 55 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.9
- 实时软连接 v2.0
- 订阅规则自动填充 v2.7
- Emby元数据刷新 v1.3
- Emby媒体标签 v1.2

View File

@@ -393,11 +393,12 @@
"name": "实时软连接",
"description": "监控目录文件变化,媒体文件软连接,其他文件可选复制。",
"labels": "文件管理",
"version": "1.9.9",
"version": "2.0",
"icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/softlink.png",
"author": "thsrite",
"level": 1,
"history": {
"v2.0": "修复交互命令",
"v1.9.9": "交互命令更多玩法",
"v1.9.8": "新增模糊匹配交互命令",
"v1.9.7": "接收云盘实时监控处理单文件",

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.9"
plugin_version = "2.0"
# 插件作者
plugin_author = "thsrite"
# 作者主页
@@ -318,30 +318,7 @@ class FileSoftLink(_PluginBase):
logger.error(f"未找到 {category} 对应的监控目录")
return
sub_paths = []
for entry in os.listdir(category):
full_path = os.path.join(category, entry)
if os.path.isdir(full_path):
sub_paths.append(full_path)
if not sub_paths:
logger.error(f"未找到 {category} 目录下的文件夹")
return
# 按照修改时间倒序排列
sub_paths.sort(key=lambda path: os.path.getmtime(path), reverse=True)
logger.info(f"开始定向处理文件夹 ...{category}, 最新 {limit} 个文件夹")
for sub_path in sub_paths[:limit]:
logger.info(f"开始定向处理文件夹 ...{sub_path}")
for sroot, sdirs, sfiles in os.walk(sub_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"{sub_path} 软连接完成!", userid=event.event_data.get("user"))
self.__handle_limit(path=category, mon_path=mon_path, limit=limit, event=event)
return
else:
for mon_path in self._categoryconf.keys():
@@ -349,36 +326,30 @@ class FileSoftLink(_PluginBase):
logger.info(f"开始检查 {mon_path} {mon_category}")
if mon_category and str(category) in mon_category:
parent_path = os.path.join(mon_path, category)
logger.info(f"获取到 {category} {args} 对应的监控目录 {parent_path}")
target_paths = self.__find_related_paths(os.path.join(str(parent_path), args))
if not target_paths:
logger.error(f"未查找到 {category} {args} 对应的具体目录")
return
handle_cnt = 0
for target_path in target_paths:
if limit is not None:
logger.info(f"开始定向处理文件夹 ...{target_path} {handle_cnt + 1}/{limit}")
else:
if limit:
logger.info(f"获取到 {category} 对应的监控目录 {parent_path}")
self.__handle_limit(path=parent_path, mon_path=mon_path, limit=limit, event=event)
else:
logger.info(f"获取到 {category} {args} 对应的监控目录 {parent_path}")
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)
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 limit is None and event_data and event_data.get("action") == "softlink_one":
return
handle_cnt += 1
# 限制处理数量
if limit and handle_cnt >= limit:
return
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 limit is None and event_data and event_data.get("action") == "softlink_one":
return
return
else:
# 遍历所有监控目录
@@ -421,7 +392,7 @@ class FileSoftLink(_PluginBase):
for sroot, sdirs, sfiles in os.walk(parent_path):
for file_name in sdirs + sfiles:
src_file = os.path.join(sroot, file_name)
if Path(src_file).is_file():
if Path(str(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"),
@@ -433,6 +404,34 @@ class FileSoftLink(_PluginBase):
title=f"{all_args} 未检索到,请检查输入是否正确!",
userid=event.event_data.get("user"))
def __handle_limit(self, path, limit, mon_path, event):
"""
处理文件数量限制
"""
sub_paths = []
for entry in os.listdir(path):
full_path = os.path.join(path, entry)
if os.path.isdir(full_path):
sub_paths.append(full_path)
if not sub_paths:
logger.error(f"未找到 {path} 目录下的文件夹")
return
# 按照修改时间倒序排列
sub_paths.sort(key=lambda path: os.path.getmtime(path), reverse=True)
logger.info(f"开始定向处理文件夹 ...{path}, 最新 {limit} 个文件夹")
for sub_path in sub_paths[:limit]:
logger.info(f"开始定向处理文件夹 ...{sub_path}")
for sroot, sdirs, sfiles in os.walk(sub_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"{sub_path} 软连接完成!", userid=event.event_data.get("user"))
@staticmethod
def __find_related_paths(base_path):
related_paths = []