another qbit fix time stamps

This commit is contained in:
2026-04-26 12:28:00 -04:00
parent 4d94ad8863
commit 0f19913c52
+21 -22
View File
@@ -364,55 +364,54 @@ QBIT_COOKIE=$(curl -s -c - \
grep SID | awk '{print "SID="$NF}') grep SID | awk '{print "SID="$NF}')
if [[ -z "$QBIT_COOKIE" ]]; then if [[ -z "$QBIT_COOKIE" ]]; then
echo "❌ Failed to authenticate with qBittorrent — check URL, username, password" echo "❌ Failed to authenticate with qBittorrent"
else else
TORRENTS=$(curl -s \ TORRENTS=$(curl -s \
"$QBIT_URL/api/v2/torrents/info" \ "$QBIT_URL/api/v2/torrents/info" \
-H "Cookie: $QBIT_COOKIE") -H "Cookie: $QBIT_COOKIE")
HASHES=$(echo "$TORRENTS" | grep -o '"hash":"[^"]*"' | \
sed 's/"hash":"//;s/"//')
NOW=$(date +%s) NOW=$(date +%s)
DELETED=0 DELETED=0
SKIPPED=0 SKIPPED=0
while IFS= read -r HASH; do # Each torrent is one JSON object — split on },{ to process individually
[[ -z "$HASH" ]] && continue echo "$TORRENTS" | tr '}' '\n' | while read -r TORRENT; do
[[ -z "$TORRENT" ]] && continue
ADDED=$(echo "$TORRENTS" | grep -A30 "\"hash\":\"$HASH\"" | \ HASH=$(echo "$TORRENT" | grep -o '"hash":"[^"]*"' | \
grep -o '"added_on":[0-9]*' | grep -o '[0-9]*' | head -1) sed 's/"hash":"//;s/"//')
RATIO=$(echo "$TORRENTS" | grep -A30 "\"hash\":\"$HASH\"" | \ NAME=$(echo "$TORRENT" | grep -o '"name":"[^"]*"' | \
grep -o '"ratio":[0-9.]*' | grep -o '[0-9.]*' | head -1) sed 's/"name":"//;s/"//')
NAME=$(echo "$TORRENTS" | grep -A30 "\"hash\":\"$HASH\"" | \ ADDED=$(echo "$TORRENT" | grep -o '"added_on":[0-9]*' | \
grep -o '"name":"[^"]*"' | sed 's/"name":"//;s/"//' | head -1) grep -o '[0-9]*')
RATIO=$(echo "$TORRENT" | grep -o '"ratio":[0-9.]*' | \
grep -o '[0-9.]*')
[[ -z "$ADDED" ]] && continue [[ -z "$HASH" || -z "$ADDED" ]] && continue
# Age in days — skip if under threshold # Age check — integer only, no bc needed
AGE_DAYS=$(( (NOW - ADDED) / 86400 )) AGE_DAYS=$(( (NOW - ADDED) / 86400 ))
[[ "$AGE_DAYS" -lt "$QBIT_FAILSAFE_MIN_DAYS" ]] && ((SKIPPED++)) && continue [[ "$AGE_DAYS" -lt "$QBIT_FAILSAFE_MIN_DAYS" ]] && continue
# Ratio gate — skip if ratio below minimum (disabled when set to 0) # Ratio check — integer comparison only, strip decimal
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_INT=${RATIO%.*}
[[ "$RATIO_OK" != "1" ]] && ((SKIPPED++)) && continue MIN_RATIO_INT=${QBIT_FAILSAFE_MIN_RATIO%.*}
[[ "$RATIO_INT" -lt "$MIN_RATIO_INT" ]] && continue
fi fi
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++))
else else
curl -s -X POST \ curl -s -X POST \
"$QBIT_URL/api/v2/torrents/delete" \ "$QBIT_URL/api/v2/torrents/delete" \
-H "Cookie: $QBIT_COOKIE" \ -H "Cookie: $QBIT_COOKIE" \
--data "hashes=$HASH&deleteFiles=false" --data "hashes=$HASH&deleteFiles=false"
echo " 🗑️ Deleted: $NAME (${AGE_DAYS} days old, ratio: $RATIO)" echo " 🗑️ Deleted: $NAME (${AGE_DAYS} days old, ratio: $RATIO)"
((DELETED++))
fi fi
done <<< "$HASHES" done
echo "✅ qBittorrent: $DELETED deleted, $SKIPPED skipped" echo "✅ qBittorrent: complete"
fi fi
echo "" echo ""