Release v1.1.0: Spotify Soloist als Empfänger, librespot als Rückfall
- soloist_api_key gesetzt (amd64/aarch64) → Spotify Soloist, sonst librespot - Soloist wird zur Laufzeit von Spotify geladen und alle 12 h aktualisiert (Builds laufen nach 90 Tagen ab) - Audio über PipeWire-Senke busch_radio → pw-record → bestehende Icecast-Pipeline - amd64/aarch64 auf Debian-Basis (glibc für Soloist), 32-Bit bleibt Alpine - Build-Fix: librespot auf Commit 99b6088 gepinnt, Browse-to-Patch an neuen Code angepasst - README, DOCS und CHANGELOG überarbeitet Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CGNdWh2jLNNb3tb9v1WEuK
This commit is contained in:
1 parent
95aac1d809
commit
99c910f488
10 files changed
+402
-114
No files matched your search
+151
-38
@@ -1,11 +1,13 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
#!/command/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Busch-Radio Spotify Bridge – Startup-Script
|
||||
#
|
||||
# Startet:
|
||||
# 1. Icecast2 – HTTP-Stream-Server
|
||||
# 2. OAuth-Hilfe – Einrichtungs-Assistent auf Port 5589
|
||||
# 3. librespot – Virtueller Spotify Connect-Empfänger (PCM auf stdout)
|
||||
# 2. Spotify-Empfänger, je nach Modus:
|
||||
# soloist – Spotifys offizieller Client → PipeWire-Senke → pw-record (PCM auf stdout)
|
||||
# librespot – Rückfall ohne API-Key bzw. auf 32-Bit (PCM auf stdout),
|
||||
# dazu OAuth-Einrichtungs-Assistent auf Port 5589
|
||||
# 4. Silence-Injektor– Fügt Stille ein wenn Spotify pausiert (hält Stream aufrecht)
|
||||
# 5. ffmpeg – Kodiert PCM → MP3/AAC und schickt es als Icecast-Quelle
|
||||
#
|
||||
@@ -21,6 +23,23 @@ STREAM_FORMAT=$(bashio::config 'stream_format')
|
||||
STREAM_PORT=$(bashio::config 'stream_port')
|
||||
STREAM_MOUNT=$(bashio::config 'stream_mount')
|
||||
ICECAST_PASSWORD=$(bashio::config 'icecast_password')
|
||||
SOLOIST_API_KEY=$(bashio::config 'soloist_api_key' '')
|
||||
|
||||
# ── Modus wählen: Soloist (mit API-Key, nur 64-Bit) oder librespot ───────────
|
||||
# librespot bekommt seit 2025/26 bei vielen Konten keine Audio-Schlüssel mehr
|
||||
# ("error audio key 0 1"); Soloist ist Spotifys offizieller Ersatz.
|
||||
MODUS="librespot"
|
||||
if [ -n "${SOLOIST_API_KEY}" ]; then
|
||||
case "$(uname -m)" in
|
||||
x86_64|aarch64)
|
||||
if soloist-fetch; [ $? -ne 1 ] || [ -x /data/soloist/bin/soloist ]; then
|
||||
MODUS="soloist"
|
||||
else
|
||||
bashio::log.warning "Soloist konnte nicht geladen werden – Rückfall auf librespot."
|
||||
fi ;;
|
||||
*) bashio::log.warning "Soloist gibt es nicht für $(uname -m) – verwende librespot." ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# ── Format-spezifische Einstellungen ──────────────────────────────────────────
|
||||
if [ "${STREAM_FORMAT}" = "aac" ]; then
|
||||
@@ -34,9 +53,10 @@ else
|
||||
fi
|
||||
|
||||
bashio::log.info "╔══════════════════════════════════════════════╗"
|
||||
bashio::log.info "║ Busch-Radio Spotify Bridge v1.0.11 ║"
|
||||
bashio::log.info "║ Busch-Radio Spotify Bridge v1.1.0 ║"
|
||||
bashio::log.info "╚══════════════════════════════════════════════╝"
|
||||
bashio::log.info "Gerätename : ${DEVICE_NAME}"
|
||||
bashio::log.info "Empfänger : ${MODUS}"
|
||||
bashio::log.info "Bitrate : ${BITRATE} kbps"
|
||||
bashio::log.info "Format : ${STREAM_FORMAT}"
|
||||
bashio::log.info "Stream-Port : ${STREAM_PORT}"
|
||||
@@ -44,8 +64,10 @@ bashio::log.info "Stream-Pfad : ${STREAM_MOUNT}"
|
||||
|
||||
# ── Verzeichnisse anlegen + Berechtigungen für nobody-User setzen ────────────
|
||||
# Icecast läuft im Container als root, wechselt aber via changeowner zu nobody.
|
||||
# Debian hat keine Gruppe "nobody", sondern "nogroup".
|
||||
NOBODY_GROUP=$(getent group nobody >/dev/null && echo nobody || echo nogroup)
|
||||
mkdir -p /var/log/icecast /run/icecast /tmp/busch-radio
|
||||
chown -R nobody:nobody /var/log/icecast /run/icecast /tmp/busch-radio
|
||||
chown -R "nobody:${NOBODY_GROUP}" /var/log/icecast /run/icecast /tmp/busch-radio
|
||||
|
||||
# ── Icecast-Webroot ermitteln ─────────────────────────────────────────────────
|
||||
# Alpine und Debian legen Icecast in unterschiedliche Pfade
|
||||
@@ -129,7 +151,7 @@ cat > /tmp/busch-radio/icecast.xml <<ICECAST_EOF
|
||||
<!-- Icecast wechselt nach dem Start zu nobody – verhindert den root-Fehler -->
|
||||
<changeowner>
|
||||
<user>nobody</user>
|
||||
<group>nobody</group>
|
||||
<group>${NOBODY_GROUP}</group>
|
||||
</changeowner>
|
||||
</security>
|
||||
</icecast>
|
||||
@@ -137,7 +159,9 @@ ICECAST_EOF
|
||||
|
||||
# ── Icecast starten ───────────────────────────────────────────────────────────
|
||||
bashio::log.info "Icecast wird gestartet (Port: ${STREAM_PORT})..."
|
||||
icecast -c /tmp/busch-radio/icecast.xml &
|
||||
# Alpine: icecast, Debian: icecast2
|
||||
ICECAST_BIN=$(command -v icecast || command -v icecast2)
|
||||
"${ICECAST_BIN}" -c /tmp/busch-radio/icecast.xml &
|
||||
ICECAST_PID=$!
|
||||
|
||||
# Kurz warten bis Icecast hochgefahren ist
|
||||
@@ -163,38 +187,42 @@ if [ -z "${HA_IP}" ]; then
|
||||
HA_IP="<homeassistant-ip>"
|
||||
fi
|
||||
|
||||
# ── OAuth-Hilfsserver starten ─────────────────────────────────────────────────
|
||||
# Stellt unter http://<ha-ip>:5589 einen Einrichtungs-Assistenten bereit,
|
||||
# der den Spotify-OAuth-Prozess Schritt für Schritt erklärt.
|
||||
python3 /oauth_helper.py "${HA_IP}" &
|
||||
OAUTH_HELPER_PID=$!
|
||||
bashio::log.info "OAuth-Hilfsseite: http://${HA_IP}:5589"
|
||||
OAUTH_HELPER_PID=""
|
||||
if [ "${MODUS}" = "librespot" ]; then
|
||||
# ── OAuth-Hilfsserver starten ─────────────────────────────────────────────────
|
||||
# Stellt unter http://<ha-ip>:5589 einen Einrichtungs-Assistenten bereit,
|
||||
# der den Spotify-OAuth-Prozess Schritt für Schritt erklärt.
|
||||
python3 /oauth_helper.py "${HA_IP}" &
|
||||
OAUTH_HELPER_PID=$!
|
||||
bashio::log.info "OAuth-Hilfsseite: http://${HA_IP}:5589"
|
||||
|
||||
# ── Librespot-Argumente zusammenstellen ───────────────────────────────────────
|
||||
LIBRESPOT_ARGS=(
|
||||
"--name" "${DEVICE_NAME}"
|
||||
"--bitrate" "${BITRATE}"
|
||||
"--backend" "pipe"
|
||||
"--device-type" "computer"
|
||||
"--disable-audio-cache"
|
||||
"--initial-volume" "100"
|
||||
"--disable-discovery"
|
||||
"--enable-oauth"
|
||||
"--system-cache" "${CREDENTIAL_CACHE}"
|
||||
)
|
||||
# ── Librespot-Argumente zusammenstellen ───────────────────────────────────────
|
||||
LIBRESPOT_ARGS=(
|
||||
"--name" "${DEVICE_NAME}"
|
||||
"--bitrate" "${BITRATE}"
|
||||
"--backend" "pipe"
|
||||
"--device-type" "computer"
|
||||
"--disable-audio-cache"
|
||||
"--initial-volume" "100"
|
||||
"--disable-discovery"
|
||||
"--enable-oauth"
|
||||
"--system-cache" "${CREDENTIAL_CACHE}"
|
||||
)
|
||||
|
||||
# Prüfen ob bereits Credentials gecacht sind
|
||||
if [ -f "${CREDENTIAL_CACHE}/credentials.json" ]; then
|
||||
bashio::log.info "Gespeicherte Credentials gefunden – Direktstart."
|
||||
else
|
||||
bashio::log.info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
bashio::log.info "ERSTER START – Spotify-Autorisierung erforderlich!"
|
||||
bashio::log.info ""
|
||||
bashio::log.info "Öffne die Einrichtungs-Seite im Browser:"
|
||||
bashio::log.info " http://${HA_IP}:5589"
|
||||
bashio::log.info ""
|
||||
bashio::log.info "Der Assistent führt dich durch die Anmeldung."
|
||||
bashio::log.info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
fi
|
||||
|
||||
# Prüfen ob bereits Credentials gecacht sind
|
||||
if [ -f "${CREDENTIAL_CACHE}/credentials.json" ]; then
|
||||
bashio::log.info "Gespeicherte Credentials gefunden – Direktstart."
|
||||
else
|
||||
bashio::log.info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
bashio::log.info "ERSTER START – Spotify-Autorisierung erforderlich!"
|
||||
bashio::log.info ""
|
||||
bashio::log.info "Öffne die Einrichtungs-Seite im Browser:"
|
||||
bashio::log.info " http://${HA_IP}:5589"
|
||||
bashio::log.info ""
|
||||
bashio::log.info "Der Assistent führt dich durch die Anmeldung."
|
||||
bashio::log.info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
fi
|
||||
|
||||
# ── Icecast-Source-URL ────────────────────────────────────────────────────────
|
||||
@@ -209,12 +237,17 @@ bashio::log.info "Icecast-Statusseite:"
|
||||
bashio::log.info " http://${HA_IP}:${STREAM_PORT}"
|
||||
bashio::log.info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
bashio::log.info "Wähle '${DEVICE_NAME}' in der Spotify-App als Abspielgerät."
|
||||
if [ "${MODUS}" = "soloist" ]; then
|
||||
bashio::log.info "Beim ersten Mal meldet sich Soloist dabei mit deinem Konto an"
|
||||
bashio::log.info "(Handy im selben Netz wie Home Assistant)."
|
||||
fi
|
||||
bashio::log.info "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
|
||||
# ── Aufräumen bei SIGTERM ─────────────────────────────────────────────────────
|
||||
cleanup() {
|
||||
bashio::log.info "Add-on wird beendet..."
|
||||
kill "${ICECAST_PID}" "${OAUTH_HELPER_PID}" 2>/dev/null || true
|
||||
kill "${ICECAST_PID}" ${OAUTH_HELPER_PID} ${SOLOIST_LOOP_PID:-} ${UPDATER_PID:-} \
|
||||
${WIREPLUMBER_PID:-} ${PIPEWIRE_PID:-} 2>/dev/null || true
|
||||
exit 0
|
||||
}
|
||||
trap cleanup SIGTERM SIGINT
|
||||
@@ -260,6 +293,86 @@ while True:
|
||||
RESTART_DELAY=5
|
||||
ATTEMPT=0
|
||||
|
||||
# ══ Modus Soloist ═════════════════════════════════════════════════════════════
|
||||
# Soloist → PipeWire-Senke "busch_radio" → pw-record (raw PCM) → Injektor → ffmpeg → Icecast
|
||||
if [ "${MODUS}" = "soloist" ]; then
|
||||
SOLOIST_BIN="/data/soloist/bin/soloist"
|
||||
SOLOIST_DATA="/data/soloist/data"
|
||||
mkdir -p /data/soloist/cache "${SOLOIST_DATA}" "${XDG_RUNTIME_DIR}"
|
||||
chmod 0700 "${SOLOIST_DATA}" "${XDG_RUNTIME_DIR}"
|
||||
|
||||
bashio::log.info "PipeWire wird gestartet..."
|
||||
pipewire &
|
||||
PIPEWIRE_PID=$!
|
||||
for _ in $(seq 1 50); do [ -S "${XDG_RUNTIME_DIR}/pipewire-0" ] && break; sleep 0.2; done
|
||||
wireplumber --profile main-embedded &
|
||||
WIREPLUMBER_PID=$!
|
||||
|
||||
# Soloist in eigener Schleife: Absturz oder abgelaufener Build → neu laden und neu starten.
|
||||
(
|
||||
while true; do
|
||||
if [ -x "${SOLOIST_BIN}.new" ]; then
|
||||
bashio::log.info "Wechsle auf neuen Soloist-Build"
|
||||
mv -f "${SOLOIST_BIN}.new" "${SOLOIST_BIN}"
|
||||
mv -f /data/soloist/bin/.etag.new /data/soloist/bin/.etag 2>/dev/null || true
|
||||
fi
|
||||
soloist-fetch || true
|
||||
bashio::log.info "Soloist wird gestartet..."
|
||||
"${SOLOIST_BIN}" \
|
||||
--device-name "${DEVICE_NAME}" \
|
||||
--api-key "${SOLOIST_API_KEY}" \
|
||||
--data-dir "${SOLOIST_DATA}" \
|
||||
--cache-dir /data/soloist/cache \
|
||||
--cache-size 200 \
|
||||
--initial-volume 100 \
|
||||
--ws 127.0.0.1:0 \
|
||||
--pipewire-device busch_radio &
|
||||
echo $! > /tmp/busch-radio/soloist.pid
|
||||
wait $! || true
|
||||
bashio::log.warning "Soloist beendet. Neustart in ${RESTART_DELAY}s..."
|
||||
sleep "${RESTART_DELAY}"
|
||||
done
|
||||
) &
|
||||
SOLOIST_LOOP_PID=$!
|
||||
|
||||
# Builds laufen nach 90 Tagen ab: alle 12 h neuen Build vormerken und
|
||||
# Soloist neu starten, sobald gerade nichts läuft.
|
||||
(
|
||||
while true; do
|
||||
sleep 43200
|
||||
soloist-fetch --stage; [ $? -eq 2 ] || continue
|
||||
while [ "$("${SOLOIST_BIN}" ctl --data-dir "${SOLOIST_DATA}" now --json 2>/dev/null \
|
||||
| jq -r '.status // empty' 2>/dev/null)" = "playing" ]; do
|
||||
sleep 60
|
||||
done
|
||||
kill "$(cat /tmp/busch-radio/soloist.pid 2>/dev/null)" 2>/dev/null || true
|
||||
done
|
||||
) &
|
||||
UPDATER_PID=$!
|
||||
|
||||
while true; do
|
||||
ATTEMPT=$((ATTEMPT + 1))
|
||||
bashio::log.info "Stream-Pipeline-Start (Versuch ${ATTEMPT})..."
|
||||
pw-record --target busch_radio -P '{ stream.capture.sink = true }' \
|
||||
--rate 44100 --channels 2 --format s16 --raw - \
|
||||
| python3 -c "${SILENCE_INJECTOR}" \
|
||||
| ffmpeg \
|
||||
-hide_banner \
|
||||
-loglevel warning \
|
||||
-f s16le -ar 44100 -ac 2 \
|
||||
-i pipe:0 \
|
||||
-codec:a "${FFMPEG_CODEC}" \
|
||||
-b:a "${BITRATE}k" \
|
||||
-f "${FFMPEG_FORMAT}" \
|
||||
"${ICECAST_SOURCE_URL}" \
|
||||
|| true
|
||||
bashio::log.warning "Stream-Pipeline beendet. Neustart in ${RESTART_DELAY}s..."
|
||||
sleep "${RESTART_DELAY}"
|
||||
done
|
||||
fi
|
||||
|
||||
# ══ Modus librespot (Rückfall) ═══════════════════════════════════════════════
|
||||
|
||||
while true; do
|
||||
ATTEMPT=$((ATTEMPT + 1))
|
||||
bashio::log.info "Pipeline-Start (Versuch ${ATTEMPT})..."
|
||||
|
||||
Reference in new issue
Block a user