Use parallel

This commit is contained in:
Jeffrey Serio 2024-05-31 11:02:50 -05:00
parent d2256b18e4
commit 2df6500045

16
qbth
View File

@ -4,7 +4,7 @@
# Dependency check
missing_deps=()
for bin in "gum" "jq" "lynx" "qbt"; do
for bin in "gum" "jq" "lynx" "parallel" "qbt"; do
if ! test -x "$(command -v $bin)"; then
missing_deps+=("$bin")
fi
@ -19,20 +19,16 @@ fi
function add_torrents() {
torrents=("$@")
for url in "${torrents[@]}"; do
if qbt torrent add url "$url"; then
gum log -l info -t ansic "Added $(basename "$url")"
else
gum log -l error -t ansic "Error adding $(basename "$url")"
fi
done
parallel qbt torrent add url ::: "${torrents[@]}"
for url in "${torrents[@]}"; do gum log -l info "Added" "$(basename $url)"; done
}
function delete_torrents() {
if test -n "$1"; then
echo "$1" | xargs -I _ sh -c "qbt torrent delete --with-files _ && gum log -l info -t ansic 'Deleted' _"
echo "$1" | parallel "qbt torrent delete --with-files {}"
echo "$1" | xargs -I _ gum log -l info "Deleted" _
else
gum log -l info -t ansic "Nothing to do."
gum log -l info "Nothing to do."
fi
}