From 2aa940bf5bbcd928048beb5b926304953acda20d Mon Sep 17 00:00:00 2001 From: Cp0204 Date: Sat, 2 Nov 2024 16:29:49 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=AD=A3=E5=88=99=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E8=A1=A8=E8=BE=BE=E5=BC=8F=E6=94=AF=E6=8C=81=20$TASKN?= =?UTF-8?q?AME=20=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quark_auto_save.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/quark_auto_save.py b/quark_auto_save.py index b1299c5..8e9efc5 100644 --- a/quark_auto_save.py +++ b/quark_auto_save.py @@ -39,12 +39,14 @@ MAGIC_REGEX = { # 魔法正则匹配 -def magic_regex_func(pattern, replace): +def magic_regex_func(pattern, replace, taskname=""): keyword = pattern if keyword in CONFIG_DATA["magic_regex"]: pattern = CONFIG_DATA["magic_regex"][keyword]["pattern"] if replace == "": replace = CONFIG_DATA["magic_regex"][keyword]["replace"] + if taskname: + replace = replace.replace("$TASKNAME", taskname) return pattern, replace @@ -531,7 +533,9 @@ class Quark: if share_file["dir"] and task.get("update_subdir", False): pattern, replace = task["update_subdir"], "" else: - pattern, replace = magic_regex_func(task["pattern"], task["replace"]) + pattern, replace = magic_regex_func( + task["pattern"], task["replace"], task["taskname"] + ) # 正则文件名匹配 if re.search(pattern, share_file["file_name"]): # 替换后的文件名 @@ -648,7 +652,9 @@ class Quark: return response def do_rename_task(self, task, subdir_path=""): - pattern, replace = magic_regex_func(task["pattern"], task["replace"]) + pattern, replace = magic_regex_func( + task["pattern"], task["replace"], task["taskname"] + ) if not pattern or not replace: return 0 savepath = re.sub(r"/{2,}", "/", f"/{task['savepath']}{subdir_path}")