arr_sync: enforce monitored on every run — bulk re-monitor unmonitored items before sync

This commit is contained in:
Gmer4Lfe
2026-06-06 18:35:41 -04:00
parent aa92511ebc
commit af313352c0
+47
View File
@@ -701,6 +701,50 @@ _build_payload() {
esac
}
# ==============================================================================================
# ── MONITORED ENFORCEMENT — re-monitor any unmonitored items via bulk editor ──────────────────
# ==============================================================================================
# All library members must be monitored. Unmonitored items won't be searched and eventually
# lose their files when cleanup runs after the series is removed from the arr.
_enforce_monitored() {
local arr_type="$1" url="$2" api_key="$3" api_ver="$4" local_json="$5"
local bulk_endpoint ids_key
case "$arr_type" in
sonarr) bulk_endpoint="series/editor"; ids_key="seriesIds" ;;
radarr) bulk_endpoint="movie/editor"; ids_key="movieIds" ;;
lidarr) bulk_endpoint="artist/editor"; ids_key="artistIds" ;;
*) return 0 ;;
esac
local ids_json count
ids_json=$(echo "$local_json" | jq '[.[] | select(.monitored == false) | .id]' 2>/dev/null)
count=$(echo "$ids_json" | jq 'length' 2>/dev/null || echo 0)
[[ "$count" -eq 0 ]] && return 0
warn "${arr_type^}: $count unmonitored items — re-monitoring"
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN: would re-monitor $count ${arr_type^} items"
return 0
fi
local body http_code
body=$(jq -n --arg k "$ids_key" --argjson ids "$ids_json" '{($k): $ids, monitored: true}')
http_code=$(curl -sf -o /dev/null -w '%{http_code}' -X PUT \
-H "X-Api-Key: $api_key" \
-H "Content-Type: application/json" \
-d "$body" \
"${url}/api/${api_ver}/${bulk_endpoint}" 2>/dev/null)
if [[ "$http_code" == "200" || "$http_code" == "202" ]]; then
log "${arr_type^}: re-monitored $count items ✅"
else
warn "${arr_type^}: bulk re-monitor failed (HTTP $http_code)"
fi
}
# ==============================================================================================
# ── CORE SYNC — one arr type across all remote nodes ──────────────────────────────────────────
# ==============================================================================================
@@ -753,6 +797,9 @@ _sync_arr() {
log "${arr_type^}: $local_count items in local library"
# ── Enforce monitored — fix any unmonitored items before sync ─────────────────────────────
_enforce_monitored "$arr_type" "$local_url" "$local_key" "$api_ver" "$local_json"
local total_added_local=0 total_added_remote=0 total_skipped=0
# ── Sync with each remote node ─────────────────────────────────────────────────────────────