admin-scripts/bin/.archived/qbt-sum-size.bash

33 lines
1.1 KiB
Bash
Raw Normal View History

2024-07-07 05:14:58 +02:00
#!/usr/bin/env bash
#
# qbt-sum-size - get the sum total size of all torrents in qBittorrent instance
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"