massive update. Master conf split, now modular with a load sceriprt to drive all configs to scripts. with unraid scpecific safeguard tests , and improved standardized ux. including dynamic host detect, who am i who else it there. EVERY SINGLE SCRIPT UPDATED. DEBATING THAT THIS IS ACUALLY V2
This commit is contained in:
@@ -1,67 +1,81 @@
|
||||
#!/bin/bash
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# --------------------------------- Arrs Failed Stalled Recovery --------------------------------
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ==============================================================================================
|
||||
# ========================= Arrs Failed / Stalled Recovery =====================================
|
||||
# ==============================================================================================
|
||||
# Automatically detects and recovers from failed imports and stalled downloads
|
||||
# across Sonarr, Radarr, and Lidarr. Blocklists the bad release and triggers
|
||||
# a new search — hands free recovery while you sleep.
|
||||
# Schedule: 0 */6 * * * (every 6 hours)
|
||||
# a new search — hands-free recovery while you sleep.
|
||||
#
|
||||
# What it checks (per-arr toggles in Master.conf):
|
||||
# HOST1: Sonarr (Tv_Shows) — /api/v3/
|
||||
# HOST1: Radarr (Movies) — /api/v3/
|
||||
# HOST1: Lidarr (Music) — /api/v1/ ← HOST1 only, exits cleanly on HOST2
|
||||
# HOST2: Sonarr (Anime_Shows) — /api/v3/
|
||||
# HOST2: Radarr (Anime_Movies) — /api/v3/
|
||||
#
|
||||
# Targets four problem types from the queue API:
|
||||
# ── WHAT IT CHECKS ────────────────────────────────────────────────────────────────────────────
|
||||
# Four problem types from the arr queue API:
|
||||
# importFailed — downloaded successfully but arr couldn't import the file
|
||||
# importPending — downloaded, stuck waiting to import (won't self-resolve)
|
||||
# error status — serious failure not covered by importFailed/importPending
|
||||
# importPending — downloaded, stuck waiting to import (will not self-resolve)
|
||||
# error status — serious failure not covered by the above two states
|
||||
# stalled — download stuck with no connections or no progress
|
||||
#
|
||||
# Items newer than ARR_IMPORT_RECOVERY_AGE (6hr) are skipped — gives arr time to retry.
|
||||
# Never touches items with state "downloading" or "imported" — safe to run anytime.
|
||||
# Items newer than ARR_IMPORT_RECOVERY_AGE are skipped — gives arr time to retry first.
|
||||
#
|
||||
# Action per problem item:
|
||||
# 1. Blocklist the release — prevents re-grabbing the same bad release
|
||||
# 2. Remove from queue — cleans up the failed item
|
||||
# 3. Trigger new search — finds a different release automatically
|
||||
# ── WHAT IT DOES PER PROBLEM ITEM ─────────────────────────────────────────────────────────────
|
||||
# 1. Blocklist the release — prevents re-grabbing the same bad release
|
||||
# 2. Remove from queue — cleans up the failed item
|
||||
# 3. Trigger new search — finds a different release automatically
|
||||
#
|
||||
# Configuration in Master.conf:
|
||||
# ARR_IMPORT_RECOVERY_AGE — hours before item is eligible
|
||||
# HOST1/2_SONARR_RECOVERY — enable/disable per arr
|
||||
# HOST1/2_RADARR_RECOVERY — enable/disable per arr
|
||||
# HOST1_LIDARR_RECOVERY — enable/disable Lidarr (HOST1 only)
|
||||
# ── HOST AWARENESS ────────────────────────────────────────────────────────────────────────────
|
||||
# detect_hosts() sets MY_ID and aliases all arr vars:
|
||||
# SONARR_URL / SONARR_API_KEY / SONARR_RECOVERY
|
||||
# RADARR_URL / RADARR_API_KEY / RADARR_RECOVERY
|
||||
# LIDARR_URL / LIDARR_API_KEY / LIDARR_RECOVERY (HOST1 only — exits cleanly on HOST2)
|
||||
# No manual HOST1/HOST2 comparisons needed — MY_ID routes automatically.
|
||||
#
|
||||
# Age threshold (ARR_IMPORT_RECOVERY_AGE):
|
||||
# Items newer than threshold are skipped — gives the arr time to retry on its own
|
||||
# Items older than threshold have not self-resolved — safe to intervene
|
||||
# Default: 12 hours
|
||||
# ── API VERSION SAFETY ────────────────────────────────────────────────────────────────────────
|
||||
# check_arr_version() verifies the running arr matches the tested major version in master.conf.
|
||||
# If the API structure changed after an upgrade — exits rather than silently misoperating.
|
||||
# Sonarr v4 → /api/v3/ (v3 endpoint retained in v4)
|
||||
# Radarr v6 → /api/v3/ (v3 endpoint retained in v6)
|
||||
# Lidarr v3 → /api/v1/ (different from Sonarr/Radarr)
|
||||
#
|
||||
# API versions:
|
||||
# Sonarr v4 → /api/v3/ (v3 endpoint retained in v4)
|
||||
# Radarr v6 → /api/v3/ (v3 endpoint retained in v6)
|
||||
# Lidarr v3 → /api/v1/ (different from Sonarr/Radarr)
|
||||
# ── SAFEGUARDS ────────────────────────────────────────────────────────────────────────────────
|
||||
# acquire_lock — prevents concurrent runs overlapping
|
||||
# jq validation — exits if jq not installed (required for JSON parsing)
|
||||
# API pre-flight — checks each arr is reachable before querying queue
|
||||
# Version check — verifies arr major version matches tested version in master.conf
|
||||
# Age threshold — skips items newer than ARR_IMPORT_RECOVERY_AGE (default 6hr)
|
||||
# Silent by default — only problems produce output, clean arrs stay silent
|
||||
#
|
||||
# Per-arr enable/disable toggles in Master.conf.
|
||||
# Lidarr runs on HOST1 only — exits cleanly on HOST2.
|
||||
# detect_hosts() selects correct URL and API key per server at runtime.
|
||||
# ── CONFIGURATION (master_host*.conf) ─────────────────────────────────────────────────────────
|
||||
# HOST*_SONARR_URL / HOST*_SONARR_API_KEY / HOST*_SONARR_RECOVERY
|
||||
# HOST*_RADARR_URL / HOST*_RADARR_API_KEY / HOST*_RADARR_RECOVERY
|
||||
# HOST1_LIDARR_URL / HOST1_LIDARR_API_KEY / HOST1_LIDARR_RECOVERY
|
||||
# All aliased by detect_hosts() — script uses unprefixed names
|
||||
#
|
||||
# Recommended schedule: 0 5 * * * (5am daily)
|
||||
# Supports --dry-run to show what would be actioned without making changes.
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ── CONFIGURATION (master.conf) ───────────────────────────────────────────────────────────────
|
||||
# ARR_IMPORT_RECOVERY_AGE — hours before item is eligible (default 6)
|
||||
# SONARR_VERSION_MAJOR — expected Sonarr major version (e.g. 4)
|
||||
# RADARR_VERSION_MAJOR — expected Radarr major version (e.g. 6)
|
||||
# LIDARR_VERSION_MAJOR — expected Lidarr major version (e.g. 3)
|
||||
# ARR_RECOVERY_STATS — stats file path (read by coffee report)
|
||||
#
|
||||
# ── USAGE ─────────────────────────────────────────────────────────────────────────────────────
|
||||
# arrs_failed_stalled_recovery.sh — normal run
|
||||
# arrs_failed_stalled_recovery.sh --dry-run — show what would be actioned, no changes
|
||||
# arrs_failed_stalled_recovery.sh --log — verbose output
|
||||
# arrs_failed_stalled_recovery.sh --status — show config and exit
|
||||
#
|
||||
# ── SCHEDULE ──────────────────────────────────────────────────────────────────────────────────
|
||||
# Recommended: 0 5 * * * (5am daily)
|
||||
# Or every 6hr: 0 */6 * * * (matches ARR_IMPORT_RECOVERY_AGE default)
|
||||
# ==============================================================================================
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
source "$SCRIPT_DIR/../Master.conf"
|
||||
source "$SCRIPT_DIR/../common.sh"
|
||||
source "$SCRIPT_DIR/../load_config.sh"
|
||||
|
||||
parse_args "$@"
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ━━━ $ICON_GEAR Setup ━━━
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ==============================================================================================
|
||||
# ━━━ Setup ━━━
|
||||
# ==============================================================================================
|
||||
echo ""
|
||||
echo "━━━ $ICON_GEAR Setup ━━━"
|
||||
|
||||
@@ -70,41 +84,73 @@ if [[ "$EUID" -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
success "Running as root"
|
||||
|
||||
acquire_lock
|
||||
|
||||
# detect_hosts() sets MY_ID and aliases SONARR_*, RADARR_*, LIDARR_* vars
|
||||
detect_hosts
|
||||
|
||||
# jq is required — not optional — for JSON parsing
|
||||
if ! command -v jq >/dev/null 2>&1; then
|
||||
error "jq is not installed — required for arr API JSON parsing"
|
||||
error "Install: apt-get install jq or brew install jq"
|
||||
notify "arrs_failed_stalled_recovery failed on $(hostname) — jq not installed" \
|
||||
"Arr Recovery" "warning"
|
||||
exit 1
|
||||
fi
|
||||
log "jq found"
|
||||
|
||||
validate_unraid_cmd \
|
||||
"/usr/local/emhttp/plugins/dynamix/scripts/notify" \
|
||||
"" "" \
|
||||
"unRAID notify script" || warn "unRAID notify script not found — native notifications disabled"
|
||||
|
||||
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no items will be blocklisted or searched"
|
||||
|
||||
# Age threshold in seconds for comparison
|
||||
# Age threshold in seconds
|
||||
AGE_THRESHOLD_SECONDS=$(( ARR_IMPORT_RECOVERY_AGE * 3600 ))
|
||||
|
||||
# Tracking totals
|
||||
TOTAL_ACTIONED=0
|
||||
TOTAL_SKIPPED=0
|
||||
ARR_SUMMARIES=()
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# CORE FUNCTIONS
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ==============================================================================================
|
||||
# ━━━ Status ━━━
|
||||
# ==============================================================================================
|
||||
if [[ "$SHOW_STATUS" == true ]]; then
|
||||
echo ""
|
||||
echo "━━━━━ $ICON_SUMMARY STATUS ━━━━━"
|
||||
echo "$ICON_HOST Identity: $MY_ID ($LOCAL_SERVER_NAME)"
|
||||
echo "$ICON_SYNC Sonarr: ${SONARR_URL:-not configured} (recovery: ${SONARR_RECOVERY:-true})"
|
||||
echo "$ICON_SYNC Radarr: ${RADARR_URL:-not configured} (recovery: ${RADARR_RECOVERY:-true})"
|
||||
echo "$ICON_SYNC Lidarr: ${LIDARR_URL:-not configured on this host} (recovery: ${LIDARR_RECOVERY:-false})"
|
||||
echo "$ICON_TIME Age thresh: ${ARR_IMPORT_RECOVERY_AGE}hr"
|
||||
echo "$ICON_GEAR Sonarr ver: v${SONARR_VERSION_MAJOR} expected"
|
||||
echo "$ICON_GEAR Radarr ver: v${RADARR_VERSION_MAJOR} expected"
|
||||
echo "$ICON_GEAR Lidarr ver: v${LIDARR_VERSION_MAJOR} expected"
|
||||
echo "$ICON_NOTIFY Notify: unRAID=${NOTIFY_UNRAID:-false} Discord=$([[ -n "${MY_DISCORD_WEBHOOK:-}" ]] && echo enabled || echo disabled)"
|
||||
echo "$ICON_GEAR Dry Run: $DRY_RUN"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ==============================================================================================
|
||||
# ── HELPER FUNCTIONS ──────────────────────────────────────────────────────────────────────────
|
||||
# ==============================================================================================
|
||||
|
||||
# Check if a queue item is older than ARR_IMPORT_RECOVERY_AGE
|
||||
# Returns 0 (old enough) or 1 (too new — skip)
|
||||
item_is_old_enough() {
|
||||
local added="$1"
|
||||
[[ -z "$added" ]] && return 0 # no date = treat as old enough
|
||||
[[ -z "$added" ]] && return 0 # no date = treat as old enough, safe to act
|
||||
local added_epoch
|
||||
added_epoch=$(date -d "$added" +%s 2>/dev/null) || return 0
|
||||
local now_epoch
|
||||
now_epoch=$(date +%s)
|
||||
local age_seconds=$(( now_epoch - added_epoch ))
|
||||
local age_seconds=$(( $(date +%s) - added_epoch ))
|
||||
[[ "$age_seconds" -ge "$AGE_THRESHOLD_SECONDS" ]]
|
||||
}
|
||||
|
||||
# Query the arr queue and return failed/stalled items
|
||||
# Query the arr queue API and return all records
|
||||
# Args: url, api_key, api_version
|
||||
get_problem_items() {
|
||||
get_queue_data() {
|
||||
local url="$1" api_key="$2" api_version="$3"
|
||||
curl -sf --max-time 15 \
|
||||
-H "X-Api-Key: $api_key" \
|
||||
@@ -112,7 +158,7 @@ get_problem_items() {
|
||||
2>/dev/null
|
||||
}
|
||||
|
||||
# Blocklist and remove item from queue
|
||||
# Blocklist and remove a queue item
|
||||
# Args: url, api_key, api_version, queue_id
|
||||
blocklist_item() {
|
||||
local url="$1" api_key="$2" api_version="$3" queue_id="$4"
|
||||
@@ -127,18 +173,18 @@ blocklist_item() {
|
||||
>/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Trigger new search
|
||||
# Trigger a new search for the media item
|
||||
# Args: url, api_key, api_version, arr_type, media_id
|
||||
trigger_search() {
|
||||
local url="$1" api_key="$2" api_version="$3" arr_type="$4" media_id="$5"
|
||||
local command body
|
||||
case "$arr_type" in
|
||||
sonarr) command="EpisodeSearch"; body="{\"name\":\"EpisodeSearch\",\"episodeIds\":[$media_id]}" ;;
|
||||
radarr) command="MoviesSearch"; body="{\"name\":\"MoviesSearch\",\"movieIds\":[$media_id]}" ;;
|
||||
lidarr) command="AlbumSearch"; body="{\"name\":\"AlbumSearch\",\"albumIds\":[$media_id]}" ;;
|
||||
sonarr) command="EpisodeSearch"; body="{\"name\":\"EpisodeSearch\",\"episodeIds\":[$media_id]}" ;;
|
||||
radarr) command="MoviesSearch"; body="{\"name\":\"MoviesSearch\",\"movieIds\":[$media_id]}" ;;
|
||||
lidarr) command="AlbumSearch"; body="{\"name\":\"AlbumSearch\",\"albumIds\":[$media_id]}" ;;
|
||||
esac
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
warn "DRY RUN — would trigger $command for ID $media_id"
|
||||
warn "DRY RUN — would trigger $command for media ID $media_id"
|
||||
return 0
|
||||
fi
|
||||
curl -sf --max-time 15 \
|
||||
@@ -150,34 +196,64 @@ trigger_search() {
|
||||
>/dev/null 2>&1
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# PROCESS AN ARR
|
||||
# Args: arr_name, arr_type, url, api_key, api_version, enabled
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ==============================================================================================
|
||||
# ── PROCESS AN ARR ────────────────────────────────────────────────────────────────────────────
|
||||
# ==============================================================================================
|
||||
# Args: display_name, arr_type, url, api_key, api_version, enabled,
|
||||
# version_major, version_api_prefix
|
||||
#
|
||||
# Exits cleanly if disabled.
|
||||
# Checks API reachability and version before touching queue.
|
||||
# Processes each problem item: blocklist + trigger new search.
|
||||
# Silent when clean — only warns when problems found or actioned.
|
||||
|
||||
process_arr() {
|
||||
local arr_name="$1" arr_type="$2" url="$3" api_key="$4" api_version="$5" enabled="$6"
|
||||
local actioned=0 skipped=0 too_new=0
|
||||
local arr_name="$1"
|
||||
local arr_type="$2"
|
||||
local url="$3"
|
||||
local api_key="$4"
|
||||
local api_version="$5"
|
||||
local enabled="$6"
|
||||
local version_major="$7"
|
||||
local version_api_prefix="$8"
|
||||
|
||||
local actioned=0 skipped_new=0
|
||||
|
||||
echo ""
|
||||
echo "━━━ $ICON_SYNC $arr_name ━━━"
|
||||
|
||||
# Disabled — skip cleanly
|
||||
if [[ "$enabled" != "true" ]]; then
|
||||
info "$arr_name recovery disabled — skipping"
|
||||
log "$arr_name recovery disabled — skipping"
|
||||
ARR_SUMMARIES+=("$arr_name: disabled")
|
||||
return
|
||||
fi
|
||||
|
||||
# API pre-flight
|
||||
# URL not configured on this host — skip cleanly
|
||||
if [[ -z "$url" ]]; then
|
||||
log "$arr_name not configured on $MY_ID — skipping"
|
||||
ARR_SUMMARIES+=("$arr_name: not configured on $MY_ID")
|
||||
return
|
||||
fi
|
||||
|
||||
# API reachability
|
||||
if ! check_api "$url" "$arr_name" 10; then
|
||||
warn "$arr_name API unreachable — skipping"
|
||||
ARR_SUMMARIES+=("$arr_name: unreachable")
|
||||
return
|
||||
fi
|
||||
|
||||
# Get queue
|
||||
# Version check — exit if API structure may have changed
|
||||
if ! check_arr_version "$url" "$api_key" "$version_api_prefix" \
|
||||
"$version_major" "$arr_name"; then
|
||||
ARR_SUMMARIES+=("$arr_name: version mismatch — skipped")
|
||||
return
|
||||
fi
|
||||
|
||||
# Fetch queue
|
||||
local queue_data
|
||||
queue_data=$(get_problem_items "$url" "$api_key" "$api_version")
|
||||
if [[ -z "$queue_data" ]] || ! command -v jq >/dev/null 2>&1; then
|
||||
queue_data=$(get_queue_data "$url" "$api_key" "$api_version")
|
||||
if [[ -z "$queue_data" ]]; then
|
||||
warn "$arr_name — could not retrieve queue data"
|
||||
ARR_SUMMARIES+=("$arr_name: queue fetch failed")
|
||||
return
|
||||
@@ -185,13 +261,9 @@ process_arr() {
|
||||
|
||||
local total_records
|
||||
total_records=$(echo "$queue_data" | jq '.totalRecords // 0' 2>/dev/null)
|
||||
info "Queue: $total_records total items"
|
||||
log "$arr_name queue: $total_records total items"
|
||||
|
||||
# Filter for problem items — never touch downloading or imported
|
||||
# importFailed = tried to import, actually failed
|
||||
# importPending = downloaded, stuck waiting to import (won't self-resolve)
|
||||
# error status = serious failure not covered by above states
|
||||
# stalled = download stuck with no connections or progress
|
||||
local problem_items
|
||||
problem_items=$(echo "$queue_data" | jq -c '
|
||||
.records // [] |
|
||||
@@ -205,48 +277,46 @@ process_arr() {
|
||||
.trackedDownloadStatus == "error" or
|
||||
(.status == "warning" and (
|
||||
(.errorMessage // "" | ascii_downcase | contains("stalled")) or
|
||||
(.statusMessages // [] | .[] | .messages // [] | .[] | ascii_downcase | contains("stalled"))
|
||||
(.statusMessages // [] | .[] | .messages // [] | .[] |
|
||||
ascii_downcase | contains("stalled"))
|
||||
))
|
||||
)
|
||||
)
|
||||
' 2>/dev/null)
|
||||
|
||||
if [[ -z "$problem_items" ]]; then
|
||||
success "$arr_name — no failed imports or stalled downloads found"
|
||||
log "$arr_name — clean ✅ no failed imports or stalled downloads"
|
||||
ARR_SUMMARIES+=("$arr_name: clean ✅")
|
||||
return
|
||||
fi
|
||||
|
||||
local problem_count
|
||||
problem_count=$(echo "$problem_items" | wc -l)
|
||||
info "Found $problem_count problem item(s)"
|
||||
warn "$arr_name — found $problem_count problem item(s)"
|
||||
|
||||
# Process each problem item
|
||||
while IFS= read -r item; do
|
||||
[[ -z "$item" ]] && continue
|
||||
|
||||
local queue_id title added problem_type media_id
|
||||
queue_id=$(echo "$item" | jq -r '.id // empty' 2>/dev/null)
|
||||
title=$(echo "$item" | jq -r '.title // "Unknown"' 2>/dev/null)
|
||||
added=$(echo "$item" | jq -r '.added // empty' 2>/dev/null)
|
||||
local queue_id title added tracked_state tracked_status problem_type media_id
|
||||
|
||||
# Determine problem type for display
|
||||
local tracked_state tracked_status
|
||||
queue_id=$(echo "$item" | jq -r '.id // empty' 2>/dev/null)
|
||||
title=$(echo "$item" | jq -r '.title // "Unknown"' 2>/dev/null)
|
||||
added=$(echo "$item" | jq -r '.added // empty' 2>/dev/null)
|
||||
tracked_state=$(echo "$item" | jq -r '.trackedDownloadState // ""' 2>/dev/null)
|
||||
tracked_status=$(echo "$item" | jq -r '.trackedDownloadStatus // ""' 2>/dev/null)
|
||||
|
||||
# Human-readable problem type
|
||||
case "$tracked_state" in
|
||||
importFailed) problem_type="import failed" ;;
|
||||
importPending) problem_type="import pending/stuck" ;;
|
||||
*)
|
||||
if [[ "$tracked_status" == "error" ]]; then
|
||||
problem_type="error"
|
||||
else
|
||||
problem_type="stalled"
|
||||
fi
|
||||
[[ "$tracked_status" == "error" ]] && \
|
||||
problem_type="error" || problem_type="stalled"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Get media ID for search trigger (episode, movie, or album)
|
||||
# Media ID for search trigger
|
||||
case "$arr_type" in
|
||||
sonarr) media_id=$(echo "$item" | jq -r '.episodeId // .episode.id // empty' 2>/dev/null) ;;
|
||||
radarr) media_id=$(echo "$item" | jq -r '.movieId // .movie.id // empty' 2>/dev/null) ;;
|
||||
@@ -255,129 +325,124 @@ process_arr() {
|
||||
|
||||
[[ -z "$queue_id" ]] && continue
|
||||
|
||||
# Age check
|
||||
# Age check — skip items that are too new to have self-resolved
|
||||
if ! item_is_old_enough "$added"; then
|
||||
info " $ICON_TIME Skipping (too new < ${ARR_IMPORT_RECOVERY_AGE}hr): $title"
|
||||
((too_new++))
|
||||
((skipped++))
|
||||
log " Skipping (too new < ${ARR_IMPORT_RECOVERY_AGE}hr): $title"
|
||||
(( skipped_new++ ))
|
||||
(( TOTAL_SKIPPED++ ))
|
||||
continue
|
||||
fi
|
||||
|
||||
info " $ICON_TRASH $problem_type: $title"
|
||||
warn " $ICON_TRASH $problem_type — $title"
|
||||
|
||||
# Blocklist + remove
|
||||
if blocklist_item "$url" "$api_key" "$api_version" "$queue_id"; then
|
||||
log " Blocklisted queue item: $queue_id"
|
||||
else
|
||||
# Step 1: Blocklist + remove from queue
|
||||
if ! blocklist_item "$url" "$api_key" "$api_version" "$queue_id"; then
|
||||
warn " Failed to blocklist: $title"
|
||||
((skipped++))
|
||||
(( TOTAL_SKIPPED++ ))
|
||||
continue
|
||||
fi
|
||||
log " Blocklisted: $queue_id"
|
||||
|
||||
# Trigger new search if we have a media ID
|
||||
# Step 2: Trigger new search
|
||||
if [[ -n "$media_id" ]]; then
|
||||
if trigger_search "$url" "$api_key" "$api_version" "$arr_type" "$media_id"; then
|
||||
log " New search triggered for: $title"
|
||||
((actioned++))
|
||||
((TOTAL_ACTIONED++))
|
||||
log " New search triggered: $title"
|
||||
else
|
||||
warn " Blocklisted but search trigger failed: $title"
|
||||
((actioned++))
|
||||
((TOTAL_ACTIONED++))
|
||||
fi
|
||||
else
|
||||
warn " Blocklisted but no media ID found for search: $title"
|
||||
((actioned++))
|
||||
((TOTAL_ACTIONED++))
|
||||
warn " Blocklisted but no media ID found — search not triggered: $title"
|
||||
fi
|
||||
|
||||
(( actioned++ ))
|
||||
(( TOTAL_ACTIONED++ ))
|
||||
|
||||
done <<< "$problem_items"
|
||||
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
info "$arr_name — dry run complete"
|
||||
if [[ "$actioned" -gt 0 ]]; then
|
||||
warn "$arr_name — actioned: $actioned | skipped (too new): $skipped_new"
|
||||
else
|
||||
success "$arr_name — actioned: $actioned | skipped (too new): $too_new"
|
||||
log "$arr_name — nothing actioned | skipped (too new): $skipped_new"
|
||||
fi
|
||||
|
||||
ARR_SUMMARIES+=("$arr_name: actioned $actioned | too new $too_new")
|
||||
TOTAL_SKIPPED=$(( TOTAL_SKIPPED + skipped ))
|
||||
ARR_SUMMARIES+=("$arr_name: actioned $actioned | too new $skipped_new")
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ━━━ $ICON_SYNC Process Each Arr ━━━
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "━━━ $ICON_SYNC Arrs Failed Stalled Recovery — $(date '+%Y-%m-%d %H:%M:%S') ━━━"
|
||||
echo "$ICON_TIME Age threshold: ${ARR_IMPORT_RECOVERY_AGE}hr (items newer than this are skipped)"
|
||||
# ==============================================================================================
|
||||
# ━━━ Process Each Arr ━━━
|
||||
# ==============================================================================================
|
||||
echo ""
|
||||
echo "━━━ $ICON_SYNC Arrs Failed/Stalled Recovery — $(date '+%Y-%m-%d %H:%M:%S') ━━━"
|
||||
echo "$ICON_HOST $MY_ID ($LOCAL_SERVER_NAME)"
|
||||
log "Age threshold: ${ARR_IMPORT_RECOVERY_AGE}hr"
|
||||
|
||||
START=$(date +%s)
|
||||
|
||||
# Sonarr
|
||||
if [[ "$LOCAL_SERVER_NAME" == "$HOST1" ]]; then
|
||||
process_arr "Sonarr (Tv_Shows)" "sonarr" \
|
||||
"$HOST1_SONARR_URL" "$HOST1_SONARR_API_KEY" "v3" \
|
||||
"${HOST1_SONARR_RECOVERY:-true}"
|
||||
else
|
||||
process_arr "Sonarr (Anime_Shows)" "sonarr" \
|
||||
"$HOST2_SONARR_URL" "$HOST2_SONARR_API_KEY" "v3" \
|
||||
"${HOST2_SONARR_RECOVERY:-true}"
|
||||
fi
|
||||
# Sonarr — uses aliased vars set by detect_hosts()
|
||||
process_arr \
|
||||
"Sonarr" \
|
||||
"sonarr" \
|
||||
"${SONARR_URL:-}" \
|
||||
"${SONARR_API_KEY:-}" \
|
||||
"v3" \
|
||||
"${SONARR_RECOVERY:-true}" \
|
||||
"${SONARR_VERSION_MAJOR:-4}" \
|
||||
"v3"
|
||||
|
||||
# Radarr
|
||||
if [[ "$LOCAL_SERVER_NAME" == "$HOST1" ]]; then
|
||||
process_arr "Radarr (Movies)" "radarr" \
|
||||
"$HOST1_RADARR_URL" "$HOST1_RADARR_API_KEY" "v3" \
|
||||
"${HOST1_RADARR_RECOVERY:-true}"
|
||||
else
|
||||
process_arr "Radarr (Anime_Movies)" "radarr" \
|
||||
"$HOST2_RADARR_URL" "$HOST2_RADARR_API_KEY" "v3" \
|
||||
"${HOST2_RADARR_RECOVERY:-true}"
|
||||
fi
|
||||
# Radarr — uses aliased vars set by detect_hosts()
|
||||
process_arr \
|
||||
"Radarr" \
|
||||
"radarr" \
|
||||
"${RADARR_URL:-}" \
|
||||
"${RADARR_API_KEY:-}" \
|
||||
"v3" \
|
||||
"${RADARR_RECOVERY:-true}" \
|
||||
"${RADARR_VERSION_MAJOR:-6}" \
|
||||
"v3"
|
||||
|
||||
# Lidarr — HOST1 only
|
||||
if [[ "$LOCAL_SERVER_NAME" == "$HOST1" ]]; then
|
||||
process_arr "Lidarr (Music)" "lidarr" \
|
||||
"$HOST1_LIDARR_URL" "$HOST1_LIDARR_API_KEY" "v1" \
|
||||
"${HOST1_LIDARR_RECOVERY:-true}"
|
||||
else
|
||||
info "Lidarr runs on $HOST1 only — skipping on $LOCAL_SERVER_NAME"
|
||||
fi
|
||||
# Lidarr — HOST1 only, LIDARR_URL empty on HOST2 → exits cleanly via "not configured" guard
|
||||
process_arr \
|
||||
"Lidarr" \
|
||||
"lidarr" \
|
||||
"${LIDARR_URL:-}" \
|
||||
"${LIDARR_API_KEY:-}" \
|
||||
"v1" \
|
||||
"${LIDARR_RECOVERY:-false}" \
|
||||
"${LIDARR_VERSION_MAJOR:-3}" \
|
||||
"v1"
|
||||
|
||||
END=$(date +%s)
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ━━━ $ICON_SUMMARY Summary ━━━
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ==============================================================================================
|
||||
# ━━━ Summary ━━━
|
||||
# ==============================================================================================
|
||||
echo ""
|
||||
echo "━━━━━ $ICON_SUMMARY ARR IMPORT RECOVERY SUMMARY ━━━━━"
|
||||
echo "$ICON_TIME Duration: $(format_duration $(( END - START )))"
|
||||
echo "$ICON_TRASH Actioned: $TOTAL_ACTIONED items blocklisted + searched"
|
||||
echo "$ICON_RUNNING Skipped: $TOTAL_SKIPPED items (too new or unreachable)"
|
||||
echo "━━━━━ $ICON_SUMMARY ARR RECOVERY SUMMARY ━━━━━"
|
||||
echo "$ICON_HOST Identity: $MY_ID ($LOCAL_SERVER_NAME)"
|
||||
echo "$ICON_TIME Duration: $(format_duration $(( END - START )))"
|
||||
echo "$ICON_TRASH Actioned: $TOTAL_ACTIONED items blocklisted + searched"
|
||||
echo "$ICON_SKIP Skipped: $TOTAL_SKIPPED items (too new)"
|
||||
echo ""
|
||||
echo " Problem types detected: importFailed | importPending | error | stalled"
|
||||
echo ""
|
||||
|
||||
for summary in "${ARR_SUMMARIES[@]}"; do
|
||||
echo " $ICON_SUMMARY $summary"
|
||||
done
|
||||
|
||||
echo ""
|
||||
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
echo "$ICON_WARN Status: DRY RUN — no changes made"
|
||||
warn "DRY RUN — no changes made"
|
||||
elif [[ "$TOTAL_ACTIONED" -gt 0 ]]; then
|
||||
echo "$ICON_DONE Status: $ICON_SUCCESS DONE"
|
||||
notify "Arr import recovery on $(hostname) — $TOTAL_ACTIONED item(s) blocklisted and re-searched. Check arrs for new downloads." "Arr Recovery" "normal"
|
||||
warn "$ICON_DONE Done — $TOTAL_ACTIONED item(s) blocklisted and re-searched"
|
||||
notify "Arr recovery on $(hostname) — $TOTAL_ACTIONED item(s) blocklisted and re-searched" \
|
||||
"Arr Recovery" "warning"
|
||||
else
|
||||
echo "$ICON_DONE Status: $ICON_SUCCESS DONE — nothing to recover"
|
||||
log "$ICON_DONE Done — nothing to recover (all arrs clean)"
|
||||
fi
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
|
||||
# Write stats for sunday_morning_coffee_report.sh
|
||||
if [[ "$DRY_RUN" == false ]] && [[ -n "${ARR_RECOVERY_STATS:-}" ]]; then
|
||||
DATE=$(date '+%Y-%m-%d')
|
||||
TIME=$(date '+%H:%M')
|
||||
echo "${DATE}|${TIME}|${TOTAL_ACTIONED}|${TOTAL_SKIPPED}" \
|
||||
echo "$(date '+%Y-%m-%d')|$(date '+%H:%M')|${TOTAL_ACTIONED}|${TOTAL_SKIPPED}" \
|
||||
>> "$ARR_RECOVERY_STATS" 2>/dev/null || true
|
||||
fi
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user