Add qbt-sum-size

This commit is contained in:
Jeffrey Serio 2024-07-05 01:10:06 -05:00
parent 2bf1e2f1ab
commit 6ce12e249c

36
bin/qbt-sum-size Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
#
# qbt-sum-size - get the sum total size of all torrents in qBittorrent instance
#
# Usage:
# qbt-sum-size added sum total size of all torrents added to instance
# qbt-sum-size completed sum total size of all completed torrents
set -euo pipefail
# Dependency check
missing_deps=()
command -v jq >/dev/null || missing_deps+=(jq)
command -v qbt >/dev/null || missing_deps+=(qbt)
if (( "${#missing_deps[@]}" != 0 )); then
echo "Missing dependencies:" "${missing_deps[@]}"
exit 1
fi
total_completed_bytes=$(qbt torrent list -F json | jq '[.[] | select(.state=="queuedUP") | .total_size | tonumber] | add')
if [ "${#total_completed_bytes}" -ge 13 ]; then
total_completed=$(echo "$total_completed_bytes" | awk '{print $1/1024/1024/1024/1024 " TiB "}')
else
total_completed=$(echo "$total_completed_bytes" | awk '{print $1/1024/1024/1024 " GiB "}')
fi
total_added_bytes=$(qbt torrent list -F json | jq '[.[].total_size | tonumber] | add')
if [ "${#total_added_bytes}" -ge 13 ]; then
total_added=$(echo "$total_added_bytes" | awk '{print $1/1024/1024/1024/1024 " TiB "}')
else
total_added=$(echo "$total_added_bytes" | awk '{print $1/1024/1024/1024 " GiB "}')
fi
printf "\nTotal completed size: %s\n" "$total_completed"
printf "Total added size: %s\n\n" "$total_added"