play_state_sync: fix jq combine fallback + detect_hosts; load_config: fix word-split on paths with spaces

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
This commit is contained in:
Gmer4Lfe
2026-05-30 00:13:26 -04:00
parent 26693fd11f
commit 23062acdac
2 changed files with 28 additions and 22 deletions
+20 -14
View File
@@ -36,10 +36,9 @@
# CONFIGURATION (host*.conf, aliased by detect_hosts) # CONFIGURATION (host*.conf, aliased by detect_hosts)
# ============================================================================================== # ==============================================================================================
# #
# HOST*_EMBY_URL Emby server URL # HOST*_TRANSCODE_SERVERS Array of "Name|URL|APIKey|type" entries (emby/jellyfin)
# HOST*_EMBY_API_KEY Emby API key # Aliased to TRANSCODE_SERVERS by detect_hosts()
# HOST*_JELLYFIN_URL Jellyfin server URL # Falls back to HOST*_EMBY_URL/KEY and HOST*_JELLYFIN_URL/KEY
# HOST*_JELLYFIN_API_KEY Jellyfin API key
# #
# master.conf # 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; } command -v jq >/dev/null 2>&1 || { error "jq is required but not installed"; exit 1; }
acquire_lock 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 declare -a SRV_NAME SRV_URL SRV_KEY SRV_TYPE
_srv_count=0 _srv_count=0
_add_server() { _add_server() {
local name="$1" url="$2" key="$3" type="$4" local name="$1" url="$2" key="$3" type="$4"
[[ -z "$url" || -z "$key" ]] && return [[ -z "$url" || -z "$key" ]] && return
# Skip placeholder/empty API keys
[[ "$key" == "YOUR_API_KEY"* || "$key" == "placeholder"* ]] && return
SRV_NAME[$_srv_count]="$name" SRV_NAME[$_srv_count]="$name"
SRV_URL[$_srv_count]="$url" SRV_URL[$_srv_count]="$url"
SRV_KEY[$_srv_count]="$key" SRV_KEY[$_srv_count]="$key"
@@ -107,15 +109,17 @@ _add_server() {
(( _srv_count++ )) (( _srv_count++ ))
} }
# Read from MEDIA_SERVERS array if set, otherwise fall back to individual vars # TRANSCODE_SERVERS is aliased from HOST*_TRANSCODE_SERVERS by detect_hosts()
if [[ ${#MEDIA_SERVERS[@]} -gt 0 ]]; then # Format: "ContainerName|URL|APIKey|Type"
for _entry in "${MEDIA_SERVERS[@]}"; do if [[ ${#TRANSCODE_SERVERS[@]} -gt 0 ]]; then
for _entry in "${TRANSCODE_SERVERS[@]}"; do
IFS='|' read -r _name _url _key _type <<< "$_entry" IFS='|' read -r _name _url _key _type <<< "$_entry"
[[ "$_type" == "emby" || "$_type" == "jellyfin" ]] && _add_server "$_name" "$_url" "$_key" "$_type" [[ "$_type" == "emby" || "$_type" == "jellyfin" ]] && _add_server "$_name" "$_url" "$_key" "$_type"
done done
else else
_add_server "${EMBY_CONTAINER:-Emby}" "${EMBY_URL:-}" "${EMBY_API_KEY:-}" "emby" # Fallback to individual vars
_add_server "${JELLYFIN_CONTAINER:-Jellyfin}" "${JELLYFIN_URL:-}" "${JELLYFIN_API_KEY:-}" "jellyfin" _add_server "${EMBY_CONTAINER:-Emby}" "${EMBY_URL:-}" "${EMBY_API_KEY:-}" "emby"
_add_server "${JELLYFIN_CONTAINER:-Jellyfin}" "${JELLYFIN_URL:-}" "${JELLYFIN_API_KEY:-}" "jellyfin"
fi fi
if [[ "$_srv_count" -lt 2 ]]; then 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") _resp2=$(_api_get "${SRV_URL[$_si]}" "${SRV_KEY[$_si]}" "$_endpoint2")
# Combine and deduplicate by Id # Combine and deduplicate by Id
_combined=$(echo "${_resp}" "${_resp2:-{\"}}" | jq -s ' if [[ -n "$_resp2" ]]; then
[.[0].Items // [], .[1].Items // []] | add // [] | _combined=$(printf '%s\n%s' "$_resp" "$_resp2" | jq -s \
unique_by(.Id) '[.[0].Items // [], .[1].Items // []] | add // [] | unique_by(.Id)' 2>/dev/null)
' 2>/dev/null) else
_combined=$(echo "$_resp" | jq '.Items // []' 2>/dev/null)
fi
_count=$(echo "$_combined" | jq 'length' 2>/dev/null || echo 0) _count=$(echo "$_combined" | jq 'length' 2>/dev/null || echo 0)
log " ${SRV_NAME[$_si]}$_count item(s) with state for $lname" log " ${SRV_NAME[$_si]}$_count item(s) with state for $lname"
+8 -8
View File
@@ -70,14 +70,14 @@
# At least one host conf must be present or the ecosystem has no identity to work with. # At least one host conf must be present or the ecosystem has no identity to work with.
_host_confs_loaded=0 _host_confs_loaded=0
for _conf in $(ls "$LOAD_CONFIG_DIR/Configurations"/host*.conf 2>/dev/null | sort); do # Use a sorted array glob — avoids word-splitting on paths with spaces
if [[ -f "$_conf" ]]; then while IFS= read -r _conf; do
source "$_conf" [[ -f "$_conf" ]] || continue
(( _host_confs_loaded++ )) source "$_conf"
[[ "${ENABLE_LOGGING:-false}" == "true" ]] && \ (( _host_confs_loaded++ ))
echo "[LOG] Loaded host config: $(basename "$_conf")" >&2 [[ "${ENABLE_LOGGING:-false}" == "true" ]] && \
fi echo "[LOG] Loaded host config: $(basename "$_conf")" >&2
done done < <(printf '%s\n' "$LOAD_CONFIG_DIR/Configurations"/host*.conf 2>/dev/null | sort)
if [[ "$_host_confs_loaded" -eq 0 ]]; then if [[ "$_host_confs_loaded" -eq 0 ]]; then
echo "[FATAL] No host*.conf files found in $LOAD_CONFIG_DIR" >&2 echo "[FATAL] No host*.conf files found in $LOAD_CONFIG_DIR" >&2