From 6cfe35d978f2cd1e8b3f79b939de9fa322b31d51 Mon Sep 17 00:00:00 2001 From: yosh Date: Sat, 3 Feb 2024 13:39:38 -0500 Subject: [PATCH] aria2sel: add --- aria2sel | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 aria2sel diff --git a/aria2sel b/aria2sel new file mode 100755 index 0000000..4bc72f1 --- /dev/null +++ b/aria2sel @@ -0,0 +1,37 @@ +#!/bin/sh +set -euf + +# wrapper script over --select-file for downloading from aria2c torrents + +# escape stuff for evaluating +escape() { + sed -e "s/^$/''/" -e "s/'/'\\\\''/g" <<-EOF + $1 + EOF +} + +errecho() { printf '%s\n' "$*" >&2; } + +FILTER_CMD="" FILTER_STR="" DOWNLOAD="" +while getopts ":dFin:" OPT; do + case "$OPT" in + d) DOWNLOAD=1 ;; + F|i) FILTER_STR="${FILTER_STR} -$OPTARG" ;; + n) + FILTER_CMD="$FILTER_CMD | grep -E ${FILTER_STR} -e '$(escape "$OPTARG")'" + ;; + *) + esac +done +shift $((OPTIND - 1)) + +[ -z "${1:-}" ] && errecho "error: torrent file needed" && exit 1 +[ -z "$FILTER_CMD" ] && errecho "error: no filters! use -n" && exit 1 + +inds=$(eval "aria2c -S '$(escape "$1")' $FILTER_CMD | cut -d '|' -f 1 | tr -d ' ' | paste -s -d ','") + +echo "$inds" + +if [ -n "$DOWNLOAD" ]; then + aria2c --select-file="$inds" "$1" +fi