Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
feat: 增加多目录监控刮削功能
Browse files Browse the repository at this point in the history
  • Loading branch information
aj.mdc.ng committed Mar 9, 2023
1 parent 0880355 commit 85c8f6b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions command.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ def update_server():
def mdc_main(
path: str,
config_ini=None,
target_folder=None,
):

target_folder = config.target_folder
if not target_folder:
target_folder = config.target_folder
proxy = config.proxies["http"]

command = ["./mdc_ng", "-p", path]
Expand All @@ -160,7 +162,7 @@ def mdc_main(
)


def mdc_dir(path: str):
def mdc_dir(path: str, target_folder=None):
videos = collect_videos(path)
if len(videos) > 0:
_LOGGER.info("[MDC] 视频文件检测到: %s" % videos)
Expand All @@ -171,7 +173,7 @@ def mdc_dir(path: str):
for video in videos:
_LOGGER.info("[MDC] 开始处理视频文件: %s" % video)
try:
mdc_main(video)
mdc_main(video, target_folder=target_folder)
except Exception as e:
_LOGGER.error("[MDC] 处理视频文件出错: %s" % video)
_LOGGER.error(e)
Expand Down
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
target_folder = ""


def init_config(web_config: dict):
def init_config(web_config: dict[str, str]):
global watch_folder, target_folder, proxies

to_watch = web_config.get("watch_folder")
if to_watch:
watch_folder = to_watch.split(",")
watch_folder = [folder.split(":") for folder in to_watch.split(",")]
logging.info("MDC插件已启用, 监视文件夹: %s" % watch_folder)

target_folder = web_config.get("target_folder") or ""
Expand Down
8 changes: 6 additions & 2 deletions event.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ def on_event(ctx: PluginContext, event_type: str, data: Dict):

_LOGGER.info("[MDC事件] watch_folder: %s " % config.watch_folder)
flag = False
target_folder = None
# 检查是否匹配监控目录配置
for dir in config.watch_folder:
for folders in config.watch_folder:
dir = folders[0]
if save_path.startswith(dir):
flag = True
if len(folders) > 1:
target_folder = folders[1]
break
if not flag:
return

_LOGGER.info("[MDC事件] 下载地址与监控目录匹配: %s, 开始执行刮削" % save_path)

mdc_dir(save_path)
mdc_dir(save_path, target_folder)
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
{
"fieldName": "watch_folder",
"fieldType": "String",
"label": "监控路径,逗号分隔",
"label": "监控路径,英文逗号分隔. 在每个监控路径后可以用英文冒号(:)附加一个该路径对应的目标路径",
"defaultValue": ""
},
{
"fieldName": "target_folder",
"fieldType": "String",
"label": "刮削整理目标路径",
"label": "默认刮削整理目标路径",
"defaultValue": ""
}
]
Expand Down

0 comments on commit 85c8f6b

Please sign in to comment.