admin-scripts/bin/qbt-sum-size
2024-07-05 01:10:06 -05:00

37 lines
1.3 KiB
Bash
Executable File

#!/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"