Shared cache (lidarr_get_tracked_data() in common.sh) so scripts stop hitting Lidarr's live API for tracked counts every run, and stop treating a mid-rescan dip as a genuine problem — a whole-library RescanFolders legitimately makes trackFileCount read far below normal while it re-verifies every file (confirmed 2026-07-16: 22% of normal mid-scan). Cache reads fresh-if-recent, waits out an active rescan (calibrated to that command's own historical duration, tracked per command name since RescanFolders and DownloadedAlbumsScan take wildly different amounts of time), then falls back to a stale cache rather than hard-failing after a few strikes. lidarr_cleanup.sh: no longer stacks a fresh DownloadedAlbumsScan on top of one already running, and the tracked-count floor check now waits out a genuine rescan instead of aborting on every overlap. lidarr_duplicate_artist_cleanup.sh (new): finds case-insensitive duplicate artist entries — same display name, different MusicBrainz ID, added when a search/list-sync matches the wrong same-named artist. Deletes the empty phantom side and blocks it from Import List Exclusions, leaves genuinely-different-real-artists alone (checked by album title overlap, deduped per-artist first so a legitimate reissue under an artist's own catalog doesn't false-flag as cross-artist overlap), and only notifies for the rare case where both sides have real, overlapping content. lidarr_cache_prefill.sh (new): warms the cache at array start so nothing reads it cold after boot. lidarr_missing_art.sh, lidarr_release_fixer.sh: write-through the cache as a side effect of fetches they already needed for their own purposes.
82 lines
3.1 KiB
Bash
Executable File
82 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# ==============================================================================================
|
|
# ================================= Lidarr Cache Prefill ========================================
|
|
# ==============================================================================================
|
|
#
|
|
# PURPOSE
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
# Populates the shared Lidarr tracked-data cache (see lidarr_get_tracked_data() in common.sh)
|
|
# once at array start, before any other script needs it. Without this, the cache stays cold
|
|
# from boot until whichever Lidarr-touching script happens to run first and write through —
|
|
# which could be hours, depending on the daily schedule. One-shot: runs and exits.
|
|
#
|
|
# ==============================================================================================
|
|
# OPERATIONAL MODEL
|
|
# ==============================================================================================
|
|
#
|
|
# Lidarr's container may still be starting when this fires (array just started) — retries
|
|
# reaching the API for up to LIDARR_PREFILL_WAIT_MINUTES before giving up. Not fatal if it
|
|
# never comes up in time; the cache just stays cold until the next script writes through
|
|
# naturally, exactly as it would without this script existing at all.
|
|
#
|
|
# ==============================================================================================
|
|
# CONFIGURATION
|
|
# ==============================================================================================
|
|
#
|
|
# host*.conf
|
|
# HOST1_LIDARR_URL / HOST1_LIDARR_API_KEY — aliased by detect_hosts()
|
|
#
|
|
# master.conf
|
|
# LIDARR_PREFILL_WAIT_MINUTES — how long to retry reaching Lidarr before giving up (default 10)
|
|
#
|
|
# ==============================================================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
source "$SCRIPT_DIR/../load_config.sh"
|
|
|
|
parse_args "$@"
|
|
|
|
if [[ "$EUID" -ne 0 ]]; then
|
|
error "Must be run as root"
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v jq >/dev/null 2>&1; then
|
|
warn "jq not found — skipping Lidarr cache prefill"
|
|
exit 0
|
|
fi
|
|
|
|
acquire_lock
|
|
|
|
detect_hosts
|
|
|
|
if [[ -z "${LIDARR_URL:-}" ]] || [[ -z "${LIDARR_API_KEY:-}" ]]; then
|
|
info "Lidarr not configured on $MY_ID ($LOCAL_SERVER_NAME) — nothing to prefill"
|
|
exit 0
|
|
fi
|
|
|
|
WAIT_MINUTES="${LIDARR_PREFILL_WAIT_MINUTES:-10}"
|
|
WAITED=0
|
|
until check_api "$LIDARR_URL" "Lidarr" 5 >/dev/null 2>&1; do
|
|
if [[ "$WAITED" -ge $(( WAIT_MINUTES * 60 )) ]]; then
|
|
warn "Lidarr not reachable after ${WAIT_MINUTES}m — leaving cache cold, next script will write through"
|
|
exit 0
|
|
fi
|
|
sleep 15
|
|
(( WAITED += 15 ))
|
|
done
|
|
|
|
ARTISTS=$(arr_api "$LIDARR_URL" "$LIDARR_API_KEY" "v1" "artist" "Lidarr") || {
|
|
warn "Could not fetch artists for cache prefill — leaving cache cold"
|
|
exit 0
|
|
}
|
|
|
|
if lidarr_cache_write "$ARTISTS"; then
|
|
log "$ICON_DONE Lidarr cache prefilled ($(echo "$ARTISTS" | jq 'length') artists)"
|
|
else
|
|
warn "Failed to write Lidarr cache prefill"
|
|
fi
|
|
|
|
exit 0
|