Skip to content

Instantly share code, notes, and snippets.

@devster31
Created Oct 24, 2021
Embed
What would you like to do?
import glob
import pathlib
from doit.tools import LongRunning
DOIT_CONFIG = {"action_string_formatting": "new"}
def aria_files():
globs = glob.glob("*.aria2.txt") + glob.glob("*.session")
files = []
for g in globs:
p = pathlib.Path(g)
if p.suffix == ".txt" and p.with_suffix(".session").name in globs:
to_add = p.with_suffix(".session").name
globs.remove(to_add)
files.append(to_add)
else:
files.append(p.name)
return files
def cmd_string(_file):
f = pathlib.Path(_file)
return (
f"aria2c --input-file {_file} "
"--load-cookies cookies.txt "
'--on-download-complete "$(pwd)"/hook.sh '
"--optimize-concurrent-downloads true "
"--show-console-readout false "
"--conditional-get true"
) + (
f" --save-session {f.with_suffix('.session').name}"
if f.suffix == ".txt"
else ""
)
def task_download():
files = aria_files()
yield {
"basename": "download",
"name": None,
"doc": "downloads input-files with aria2",
}
for f in files:
cmd = cmd_string(f)
yield {
"name": f,
"actions": [LongRunning(cmd)],
"verbosity": 2,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment