From 6ce12e249c5cc34764b7f925848d4db021911e6a Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Fri, 5 Jul 2024 01:10:06 -0500 Subject: [PATCH] Add qbt-sum-size --- bin/qbt-sum-size | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 bin/qbt-sum-size diff --git a/bin/qbt-sum-size b/bin/qbt-sum-size new file mode 100755 index 0000000..1305b6b --- /dev/null +++ b/bin/qbt-sum-size @@ -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"