diff --git a/Tools/downloaders_reset.sh b/Tools/downloaders_reset.sh index 65223e5..219d590 100644 --- a/Tools/downloaders_reset.sh +++ b/Tools/downloaders_reset.sh @@ -57,11 +57,10 @@ QBIT_URL="http://localhost:8080" QBIT_USERNAME="admin" QBIT_PASSWORD="changeme" -# Last chance failsafe — deletes torrents older than this many days -# regardless of ratio. qBittorrent's own rules handle normal cleanup -# (ratio >= 1.25 OR 45 days inactive). This catches anything missed -# after an extended period. Set ratio gate to 0 to disable ratio check -# and use age as the only condition. +# Last chance failsafe — deletes torrents older than this many days. +# qBittorrent's own rules handle normal cleanup (ratio >= 1.25 OR 45 days +# inactive). This catches anything missed after an extended period. +# QBIT_FAILSAFE_MIN_RATIO=0 disables ratio gate — age is the only condition. QBIT_FAILSAFE_MIN_DAYS=180 QBIT_FAILSAFE_MIN_RATIO=0 @@ -349,6 +348,8 @@ echo "" # qBittorrent's own rules handle normal cleanup (ratio >= 1.25 OR 45 days # inactive). This catches anything missed after extended time. # 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 "🔍 qBittorrent — Failsafe Cleanup" @@ -357,7 +358,6 @@ echo " Age > ${QBIT_FAILSAFE_MIN_DAYS} days" echo " Ratio >= ${QBIT_FAILSAFE_MIN_RATIO}" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -# Login to qBittorrent and get session cookie QBIT_COOKIE=$(curl -s -c - \ "$QBIT_URL/api/v2/auth/login" \ --data "username=$QBIT_USERNAME&password=$QBIT_PASSWORD" | \ @@ -374,15 +374,12 @@ else sed 's/"hash":"//;s/"//') NOW=$(date +%s) - CUTOFF_AGE=$(( NOW - (QBIT_FAILSAFE_MIN_DAYS * 86400) )) - DELETED=0 SKIPPED=0 while IFS= read -r HASH; do [[ -z "$HASH" ]] && continue - # Get added_on timestamp and ratio for this torrent ADDED=$(echo "$TORRENTS" | grep -A30 "\"hash\":\"$HASH\"" | \ grep -o '"added_on":[0-9]*' | grep -o '[0-9]*' | head -1) RATIO=$(echo "$TORRENTS" | grep -A30 "\"hash\":\"$HASH\"" | \ @@ -392,17 +389,16 @@ else [[ -z "$ADDED" ]] && continue - # Check age gate - [[ "$ADDED" -gt "$CUTOFF_AGE" ]] && ((SKIPPED++)) && continue + # Age in days — skip if under threshold + 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 RATIO_OK=$(echo "$RATIO >= $QBIT_FAILSAFE_MIN_RATIO" | bc -l 2>/dev/null) [[ "$RATIO_OK" != "1" ]] && ((SKIPPED++)) && continue fi - AGE_DAYS=$(( (NOW - ADDED) / 86400 )) - if $DRY_RUN; then echo "🧪 Would delete: $NAME (${AGE_DAYS} days old, ratio: $RATIO)" ((DELETED++))