update radar and sonarr enpoints

This commit is contained in:
2026-04-26 01:19:32 -04:00
parent 3df4542351
commit e6a6bfd5e9
3 changed files with 65 additions and 14 deletions
+30 -6
View File
@@ -212,21 +212,45 @@ check_api "$SONARR_URL" "Sonarr" || {
info "Querying Sonarr API: $SONARR_URL"
EPISODEFILE_RESPONSE=$(sonarr_api "episodefile") || {
error "Failed to fetch episode files from Sonarr — check URL and API key"
# Step 1 — get all series to extract IDs
SERIES_RESPONSE=$(sonarr_api "series") || {
error "Failed to fetch series from Sonarr — check URL and API key"
notify "Sonarr cleanup failed on $(hostname) — API unreachable" "Sonarr Cleanup" "warning"
exit 1
}
SERIES_IDS=$(echo "$SERIES_RESPONSE" | jq -r '.[].id' 2>/dev/null)
SERIES_COUNT=$(echo "$SERIES_IDS" | grep -c . 2>/dev/null || echo 0)
info "Series in Sonarr: $SERIES_COUNT"
if [[ "$SERIES_COUNT" -eq 0 ]]; then
warn "No series returned from Sonarr — aborting to prevent mass deletion"
notify "Sonarr cleanup aborted on $(hostname) — no series returned from API" "Sonarr Cleanup" "warning"
exit 1
fi
TMP_DIR="/tmp/sonarr_cleanup_$$"
mkdir -p "$TMP_DIR"
trap "rm -rf $TMP_DIR" EXIT
TRACKED_FILE="$TMP_DIR/tracked_paths.txt"
while IFS= read -r api_path; do
[[ -z "$api_path" ]] && continue
translate_path "$api_path" >> "$TRACKED_FILE"
done < <(echo "$EPISODEFILE_RESPONSE" | jq -r '.[].path' 2>/dev/null)
> "$TRACKED_FILE"
# Step 2 — get episode files per series ID
SERIES_INDEX=0
while IFS= read -r series_id; do
[[ -z "$series_id" ]] && continue
((SERIES_INDEX++))
[[ $(( SERIES_INDEX % 50 )) -eq 0 ]] && info "Fetching files: $SERIES_INDEX/$SERIES_COUNT series..."
SERIES_FILES=$(sonarr_api "episodefile?seriesId=${series_id}" 2>/dev/null)
if [[ -n "$SERIES_FILES" ]]; then
while IFS= read -r api_path; do
[[ -z "$api_path" ]] && continue
translate_path "$api_path" >> "$TRACKED_FILE"
done < <(echo "$SERIES_FILES" | jq -r '.[].path' 2>/dev/null)
fi
done <<< "$SERIES_IDS"
sort -u "$TRACKED_FILE" -o "$TRACKED_FILE"
TRACKED_COUNT=$(wc -l < "$TRACKED_FILE")