From 23062acdacf029520550377ca54e95804ef717c3 Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Sat, 30 May 2026 00:13:26 -0400 Subject: [PATCH] play_state_sync: fix jq combine fallback + detect_hosts; load_config: fix word-split on paths with spaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit play_state_sync.sh: - Add detect_hosts() call so TRANSCODE_SERVERS alias is populated - Switch MEDIA_SERVERS → TRANSCODE_SERVERS (correct array name from host*.conf) - Fix malformed jq fallback in combine step (was {"} now handled with if/else) - Skip placeholder API keys in _add_server load_config.sh: - Replace 'for x in $(ls glob)' with 'while read < <(printf glob | sort)' so paths with spaces (e.g. dev workspace) don't get word-split --- Media/play_state_sync.sh | 34 ++++++++++++++++++++-------------- load_config.sh | 16 ++++++++-------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Media/play_state_sync.sh b/Media/play_state_sync.sh index a5e607e..33d8b4e 100755 --- a/Media/play_state_sync.sh +++ b/Media/play_state_sync.sh @@ -36,10 +36,9 @@ # CONFIGURATION (host*.conf, aliased by detect_hosts) # ============================================================================================== # -# HOST*_EMBY_URL Emby server URL -# HOST*_EMBY_API_KEY Emby API key -# HOST*_JELLYFIN_URL Jellyfin server URL -# HOST*_JELLYFIN_API_KEY Jellyfin API key +# HOST*_TRANSCODE_SERVERS Array of "Name|URL|APIKey|type" entries (emby/jellyfin) +# Aliased to TRANSCODE_SERVERS by detect_hosts() +# Falls back to HOST*_EMBY_URL/KEY and HOST*_JELLYFIN_URL/KEY # # master.conf # @@ -92,14 +91,17 @@ SYNC_TYPES="${PLAY_SYNC_TYPES:-Movie,Episode,Audio}" command -v jq >/dev/null 2>&1 || { error "jq is required but not installed"; exit 1; } acquire_lock +detect_hosts -# ── Build server list ───────────────────────────────────────────────────────── +# ── Build server list from TRANSCODE_SERVERS (aliased by detect_hosts) ──────── declare -a SRV_NAME SRV_URL SRV_KEY SRV_TYPE _srv_count=0 _add_server() { local name="$1" url="$2" key="$3" type="$4" [[ -z "$url" || -z "$key" ]] && return + # Skip placeholder/empty API keys + [[ "$key" == "YOUR_API_KEY"* || "$key" == "placeholder"* ]] && return SRV_NAME[$_srv_count]="$name" SRV_URL[$_srv_count]="$url" SRV_KEY[$_srv_count]="$key" @@ -107,15 +109,17 @@ _add_server() { (( _srv_count++ )) } -# Read from MEDIA_SERVERS array if set, otherwise fall back to individual vars -if [[ ${#MEDIA_SERVERS[@]} -gt 0 ]]; then - for _entry in "${MEDIA_SERVERS[@]}"; do +# TRANSCODE_SERVERS is aliased from HOST*_TRANSCODE_SERVERS by detect_hosts() +# Format: "ContainerName|URL|APIKey|Type" +if [[ ${#TRANSCODE_SERVERS[@]} -gt 0 ]]; then + for _entry in "${TRANSCODE_SERVERS[@]}"; do IFS='|' read -r _name _url _key _type <<< "$_entry" [[ "$_type" == "emby" || "$_type" == "jellyfin" ]] && _add_server "$_name" "$_url" "$_key" "$_type" done else - _add_server "${EMBY_CONTAINER:-Emby}" "${EMBY_URL:-}" "${EMBY_API_KEY:-}" "emby" - _add_server "${JELLYFIN_CONTAINER:-Jellyfin}" "${JELLYFIN_URL:-}" "${JELLYFIN_API_KEY:-}" "jellyfin" + # Fallback to individual vars + _add_server "${EMBY_CONTAINER:-Emby}" "${EMBY_URL:-}" "${EMBY_API_KEY:-}" "emby" + _add_server "${JELLYFIN_CONTAINER:-Jellyfin}" "${JELLYFIN_URL:-}" "${JELLYFIN_API_KEY:-}" "jellyfin" fi if [[ "$_srv_count" -lt 2 ]]; then @@ -276,10 +280,12 @@ for lname in "${!USER_MAP[@]}"; do _resp2=$(_api_get "${SRV_URL[$_si]}" "${SRV_KEY[$_si]}" "$_endpoint2") # Combine and deduplicate by Id - _combined=$(echo "${_resp}" "${_resp2:-{\"}}" | jq -s ' - [.[0].Items // [], .[1].Items // []] | add // [] | - unique_by(.Id) - ' 2>/dev/null) + if [[ -n "$_resp2" ]]; then + _combined=$(printf '%s\n%s' "$_resp" "$_resp2" | jq -s \ + '[.[0].Items // [], .[1].Items // []] | add // [] | unique_by(.Id)' 2>/dev/null) + else + _combined=$(echo "$_resp" | jq '.Items // []' 2>/dev/null) + fi _count=$(echo "$_combined" | jq 'length' 2>/dev/null || echo 0) log " ${SRV_NAME[$_si]} — $_count item(s) with state for $lname" diff --git a/load_config.sh b/load_config.sh index 45a28a5..1128d0b 100644 --- a/load_config.sh +++ b/load_config.sh @@ -70,14 +70,14 @@ # At least one host conf must be present or the ecosystem has no identity to work with. _host_confs_loaded=0 - for _conf in $(ls "$LOAD_CONFIG_DIR/Configurations"/host*.conf 2>/dev/null | sort); do - if [[ -f "$_conf" ]]; then - source "$_conf" - (( _host_confs_loaded++ )) - [[ "${ENABLE_LOGGING:-false}" == "true" ]] && \ - echo "[LOG] Loaded host config: $(basename "$_conf")" >&2 - fi - done + # Use a sorted array glob — avoids word-splitting on paths with spaces + while IFS= read -r _conf; do + [[ -f "$_conf" ]] || continue + source "$_conf" + (( _host_confs_loaded++ )) + [[ "${ENABLE_LOGGING:-false}" == "true" ]] && \ + echo "[LOG] Loaded host config: $(basename "$_conf")" >&2 + done < <(printf '%s\n' "$LOAD_CONFIG_DIR/Configurations"/host*.conf 2>/dev/null | sort) if [[ "$_host_confs_loaded" -eq 0 ]]; then echo "[FATAL] No host*.conf files found in $LOAD_CONFIG_DIR" >&2