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
+18 -12
View File
@@ -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,13 +109,15 @@ _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
# 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
@@ -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"
+4 -4
View File
@@ -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
# 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
fi
done
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