Skip to content

Instantly share code, notes, and snippets.

@devster31
Created October 24, 2021 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devster31/1c601a14b9d4ea710a09073c5ae8feb0 to your computer and use it in GitHub Desktop.
Save devster31/1c601a14b9d4ea710a09073c5ae8feb0 to your computer and use it in GitHub Desktop.
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