i age retention fix for qbit in downloaders reset

This commit is contained in:
2026-04-26 12:21:27 -04:00
parent 516f6996bc
commit 4d94ad8863
+10 -14
View File
@@ -57,11 +57,10 @@ QBIT_URL="http://localhost:8080"
QBIT_USERNAME="admin" QBIT_USERNAME="admin"
QBIT_PASSWORD="changeme" QBIT_PASSWORD="changeme"
# Last chance failsafe — deletes torrents older than this many days # Last chance failsafe — deletes torrents older than this many days.
# regardless of ratio. qBittorrent's own rules handle normal cleanup # qBittorrent's own rules handle normal cleanup (ratio >= 1.25 OR 45 days
# (ratio >= 1.25 OR 45 days inactive). This catches anything missed # inactive). This catches anything missed after an extended period.
# after an extended period. Set ratio gate to 0 to disable ratio check # QBIT_FAILSAFE_MIN_RATIO=0 disables ratio gate — age is the only condition.
# and use age as the only condition.
QBIT_FAILSAFE_MIN_DAYS=180 QBIT_FAILSAFE_MIN_DAYS=180
QBIT_FAILSAFE_MIN_RATIO=0 QBIT_FAILSAFE_MIN_RATIO=0
@@ -349,6 +348,8 @@ echo ""
# qBittorrent's own rules handle normal cleanup (ratio >= 1.25 OR 45 days # qBittorrent's own rules handle normal cleanup (ratio >= 1.25 OR 45 days
# inactive). This catches anything missed after extended time. # inactive). This catches anything missed after extended time.
# QBIT_FAILSAFE_MIN_RATIO=0 disables ratio gate — age is the only condition. # QBIT_FAILSAFE_MIN_RATIO=0 disables ratio gate — age is the only condition.
# deleteFiles=false — removes torrent from qBit but leaves files on disk.
# Radarr/Sonarr manage the actual files independently.
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🔍 qBittorrent — Failsafe Cleanup" echo "🔍 qBittorrent — Failsafe Cleanup"
@@ -357,7 +358,6 @@ echo " Age > ${QBIT_FAILSAFE_MIN_DAYS} days"
echo " Ratio >= ${QBIT_FAILSAFE_MIN_RATIO}" echo " Ratio >= ${QBIT_FAILSAFE_MIN_RATIO}"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Login to qBittorrent and get session cookie
QBIT_COOKIE=$(curl -s -c - \ QBIT_COOKIE=$(curl -s -c - \
"$QBIT_URL/api/v2/auth/login" \ "$QBIT_URL/api/v2/auth/login" \
--data "username=$QBIT_USERNAME&password=$QBIT_PASSWORD" | \ --data "username=$QBIT_USERNAME&password=$QBIT_PASSWORD" | \
@@ -374,15 +374,12 @@ else
sed 's/"hash":"//;s/"//') sed 's/"hash":"//;s/"//')
NOW=$(date +%s) NOW=$(date +%s)
CUTOFF_AGE=$(( NOW - (QBIT_FAILSAFE_MIN_DAYS * 86400) ))
DELETED=0 DELETED=0
SKIPPED=0 SKIPPED=0
while IFS= read -r HASH; do while IFS= read -r HASH; do
[[ -z "$HASH" ]] && continue [[ -z "$HASH" ]] && continue
# Get added_on timestamp and ratio for this torrent
ADDED=$(echo "$TORRENTS" | grep -A30 "\"hash\":\"$HASH\"" | \ ADDED=$(echo "$TORRENTS" | grep -A30 "\"hash\":\"$HASH\"" | \
grep -o '"added_on":[0-9]*' | grep -o '[0-9]*' | head -1) grep -o '"added_on":[0-9]*' | grep -o '[0-9]*' | head -1)
RATIO=$(echo "$TORRENTS" | grep -A30 "\"hash\":\"$HASH\"" | \ RATIO=$(echo "$TORRENTS" | grep -A30 "\"hash\":\"$HASH\"" | \
@@ -392,17 +389,16 @@ else
[[ -z "$ADDED" ]] && continue [[ -z "$ADDED" ]] && continue
# Check age gate # Age in days — skip if under threshold
[[ "$ADDED" -gt "$CUTOFF_AGE" ]] && ((SKIPPED++)) && continue AGE_DAYS=$(( (NOW - ADDED) / 86400 ))
[[ "$AGE_DAYS" -lt "$QBIT_FAILSAFE_MIN_DAYS" ]] && ((SKIPPED++)) && continue
# Check ratio gate if enabled # Ratio gate — skip if ratio below minimum (disabled when set to 0)
if [[ "$QBIT_FAILSAFE_MIN_RATIO" != "0" ]]; then if [[ "$QBIT_FAILSAFE_MIN_RATIO" != "0" ]]; then
RATIO_OK=$(echo "$RATIO >= $QBIT_FAILSAFE_MIN_RATIO" | bc -l 2>/dev/null) RATIO_OK=$(echo "$RATIO >= $QBIT_FAILSAFE_MIN_RATIO" | bc -l 2>/dev/null)
[[ "$RATIO_OK" != "1" ]] && ((SKIPPED++)) && continue [[ "$RATIO_OK" != "1" ]] && ((SKIPPED++)) && continue
fi fi
AGE_DAYS=$(( (NOW - ADDED) / 86400 ))
if $DRY_RUN; then if $DRY_RUN; then
echo "🧪 Would delete: $NAME (${AGE_DAYS} days old, ratio: $RATIO)" echo "🧪 Would delete: $NAME (${AGE_DAYS} days old, ratio: $RATIO)"
((DELETED++)) ((DELETED++))