mirror of
https://codeberg.org/hyperreal/admin-scripts
synced 2024-11-25 09:03:41 +01:00
Add qbt-sum-size
This commit is contained in:
parent
2bf1e2f1ab
commit
6ce12e249c
36
bin/qbt-sum-size
Executable file
36
bin/qbt-sum-size
Executable 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"
|
Loading…
Reference in New Issue
Block a user