插件 aria2 添加暂停选项

- 增加暂停选项,可仅添加任务不下载
- 优化任务选项读取逻辑
This commit is contained in:
Cp0204 2024-11-27 01:13:33 +08:00
parent 10030346d0
commit 7e612541a4

View File

@ -10,7 +10,8 @@ class Aria2:
"dir": "/Downloads", # 下载目录需要Aria2有权限访问 "dir": "/Downloads", # 下载目录需要Aria2有权限访问
} }
default_task_config = { default_task_config = {
"auto_download": False, # 是否开启自动下载 "auto_download": False, # 是否自动添加下载任务
"pause": False, # 添加任务后为暂停状态,不自动开始(手动下载)
} }
is_active = False is_active = False
rpc_url = None rpc_url = None
@ -29,9 +30,11 @@ class Aria2:
self.is_active = True self.is_active = True
def run(self, task, **kwargs): def run(self, task, **kwargs):
if task_config := task.get("addition", {}).get(self.plugin_name, {}): task_config = task.get("addition", {}).get(
if not task_config.get("auto_download"): self.plugin_name, self.default_task_config
return )
if not task_config.get("auto_download"):
return
if (tree := kwargs.get("tree")) and (account := kwargs.get("account")): if (tree := kwargs.get("tree")) and (account := kwargs.get("account")):
for node in tree.all_nodes_itr(): for node in tree.all_nodes_itr():
if not node.data.get("is_dir", True): if not node.data.get("is_dir", True):
@ -52,6 +55,7 @@ class Aria2:
], ],
"out": os.path.basename(save_path), "out": os.path.basename(save_path),
"dir": os.path.dirname(save_path), "dir": os.path.dirname(save_path),
"pause": task_config.get("pause"),
}, },
] ]
self.add_uri(aria2_params) self.add_uri(aria2_params)