Bash common.sh: consolidate docker_cmd/retry_docker/verify_running/emby_api, fix tailscale dups

common.sh gains:
- docker_cmd() + verify_running() + retry_docker() — removed from all 3 Docker_Essentials
  scripts where they were byte-for-byte duplicates
- emby_api(endpoint, [timeout=30]) — removed from 6 Media/Tools scripts that each defined
  their own _emby_api() with the same curl/parse/error pattern; call sites renamed emby_api
- format_duration() extended with days/hours branch (was capped at minutes+seconds)
- notify() comment: scripts do not need to preflight the notify script via validate_unraid_cmd

Tailscale deduplication:
- arr_sync.sh: _resolve_node_ip() and inline block in _delete_remote_item() both replaced
  with resolve_tailscale_ip() from common.sh
- git_pull_execute.sh: inline tailscale ip -4 replaced with resolve_tailscale_ip() (adds
  the tailscale status fallback that was missing)
This commit is contained in:
Gmer4Lfe
2026-06-04 17:00:50 -04:00
parent 0bcb773332
commit b5d33cd6a5
12 changed files with 98 additions and 238 deletions
+3 -14
View File
@@ -90,17 +90,6 @@ fi
# ── API HELPERS ───────────────────────────────────────────────────────────────────────────────
# ==============================================================================================
_emby_api() {
local response http_code body
response=$(curl -sf --max-time 30 \
-H "X-Emby-Token: $EMBY_API_KEY" \
-w "\n%{http_code}" \
"${EMBY_URL}/${1}" 2>/dev/null)
http_code=$(echo "$response" | tail -1)
body=$(echo "$response" | head -n -1)
[[ "$http_code" != "200" ]] && { error "Emby API HTTP $http_code: $1"; return 1; }
echo "$body"
}
_radarr_get() {
curl -sf --max-time 30 \
@@ -160,7 +149,7 @@ echo "━━━ $ICON_SYNC Emby Movie Library ━━━"
declare -A EMBY_MOVIES # name → tmdb_id (empty string if none)
if [[ "${#RADARR_EMBY_LIBRARIES[@]}" -gt 0 ]]; then
LIBRARIES_JSON=$(_emby_api "Library/VirtualFolders") || { error "Could not fetch Emby libraries"; exit 1; }
LIBRARIES_JSON=$(emby_api "Library/VirtualFolders") || { error "Could not fetch Emby libraries"; exit 1; }
for lib_name in "${RADARR_EMBY_LIBRARIES[@]}"; do
lib_id=$(echo "$LIBRARIES_JSON" | jq -r --arg n "$lib_name" '.[] | select(.Name == $n) | .ItemId' 2>/dev/null)
if [[ -z "$lib_id" ]]; then
@@ -168,7 +157,7 @@ if [[ "${#RADARR_EMBY_LIBRARIES[@]}" -gt 0 ]]; then
continue
fi
log "Scanning library: $lib_name (ItemId: $lib_id)"
LIB_JSON=$(_emby_api "Items?ParentId=${lib_id}&IncludeItemTypes=Movie&Recursive=true&Fields=ProviderIds&Limit=5000") || {
LIB_JSON=$(emby_api "Items?ParentId=${lib_id}&IncludeItemTypes=Movie&Recursive=true&Fields=ProviderIds&Limit=5000") || {
warn "Could not fetch movies from library: $lib_name"
continue
}
@@ -180,7 +169,7 @@ if [[ "${#RADARR_EMBY_LIBRARIES[@]}" -gt 0 ]]; then
done
else
log "RADARR_EMBY_LIBRARIES empty — scanning all Emby libraries"
EMBY_MOVIES_JSON=$(_emby_api "Items?IncludeItemTypes=Movie&Recursive=true&Fields=ProviderIds&Limit=10000") || {
EMBY_MOVIES_JSON=$(emby_api "Items?IncludeItemTypes=Movie&Recursive=true&Fields=ProviderIds&Limit=10000") || {
error "Could not fetch Emby movies"
exit 1
}