From 99c910f488c5766e5b5837082deebfee16519e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20G=C3=BChne?= <42kdesigners@gmail.com> Date: Wed, 4 Nov 2026 15:26:50 +0100 Subject: [PATCH] =?UTF-8?q?Release=20v1.1.0:=20Spotify=20Soloist=20als=20E?= =?UTF-8?q?mpf=C3=A4nger,=20librespot=20als=20R=C3=BCckfall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 Claude-Session: https://claude.ai/code/session_01CGNdWh2jLNNb3tb9v1WEuK --- README.md | 64 ++++-- busch_radio_spotify/CHANGELOG.md | 13 ++ busch_radio_spotify/DOCS.md | 70 +++---- busch_radio_spotify/Dockerfile | 56 ++++-- busch_radio_spotify/build.yaml | 7 +- busch_radio_spotify/config.yaml | 9 +- .../pipewire/10-busch-radio.conf | 25 +++ busch_radio_spotify/run.sh | 189 ++++++++++++++---- busch_radio_spotify/soloist-fetch.sh | 68 +++++++ .../wireplumber/10-busch-radio.conf | 15 ++ 10 files changed, 402 insertions(+), 114 deletions(-) create mode 100644 busch_radio_spotify/pipewire/10-busch-radio.conf create mode 100644 busch_radio_spotify/soloist-fetch.sh create mode 100644 busch_radio_spotify/wireplumber/10-busch-radio.conf diff --git a/README.md b/README.md index fb646fc..042292c 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,20 @@ Das **Busch-Jäger Unterputz-Internetradio** kann nur Internetradio-Streams absp ## Lösung -Dieses Home Assistant Add-on erstellt ein virtuelles Spotify Connect-Gerät ([librespot](https://github.com/librespot-org/librespot)) und stellt das Audio als MP3- oder AAC-Stream über Icecast bereit. +Dieses Home Assistant Add-on erstellt ein virtuelles Spotify Connect-Gerät und stellt das Audio als MP3- oder AAC-Stream über Icecast bereit. + +Als Spotify-Empfänger dient ab Version 1.1.0 **[Spotify Soloist](https://developer.spotify.com)**, Spotifys offizieller Client für Linux. +Ohne Soloist-API-Key (und auf 32-Bit-Geräten) läuft weiterhin **[librespot](https://github.com/librespot-org/librespot)** als Rückfall. + +> **Warum Soloist?** Spotify verweigert librespot seit 2025/26 bei vielen Konten die Audio-Schlüssel. +> Im Log erscheint dann bei jedem Titel `error audio key 0 1` und es bleibt still +> ([librespot #1649](https://github.com/librespot-org/librespot/issues/1649)). Mit Soloist tritt das nicht auf. ### Funktionsweise ``` -Spotify-App → [Spotify Connect] → librespot → PCM → ffmpeg → Icecast2 → HTTP-Stream → Busch-Jäger Radio +Spotify-App → [Spotify Connect] → Soloist → PipeWire → pw-record ─┐ + librespot (Rückfall) ───────────┴→ PCM → ffmpeg → Icecast → Busch-Jäger Radio ``` --- @@ -31,7 +39,9 @@ Spotify-App → [Spotify Connect] → librespot → PCM → ffmpeg → Icecast2 | Anforderung | Details | |---|---| | Home Assistant | OS, Supervised oder Container | -| Spotify Premium | Pflicht für Spotify Connect | +| Spotify Premium | Pflicht für Spotify Connect und für den Soloist-API-Key | +| Architektur | Soloist: amd64 oder aarch64 (z. B. Raspberry Pi 4/5 mit 64-Bit-OS); 32-Bit nur librespot | +| Internet | Soloist wird beim Start von Spotify geladen und alle 12 h aktualisiert | | Busch-Jäger Radio | Muss benutzerdefinierte Stream-URLs unterstützen | --- @@ -55,9 +65,23 @@ stream_format: "mp3" # mp3 oder aac stream_port: 8000 # HTTP-Port des Streams stream_mount: "/stream" # URL-Pfad icecast_password: "geheim" # Icecast-Passwort (bitte ändern) +soloist_api_key: "" # Soloist-API-Key (leer = librespot) ``` -### 3. Add-on starten & Spotify autorisieren +### 3a. Mit Soloist (empfohlen) + +1. Im [Spotify-for-Developers-Dashboard](https://developer.spotify.com/dashboard) mit dem **Premium-Konto** anmelden +2. Im Bereich **Soloist API Key** einen Schlüssel erzeugen +3. Schlüssel in `soloist_api_key` eintragen, speichern, Add-on (neu) starten +4. Im Log steht `Empfänger : soloist` +5. Spotify-App öffnen (Handy **im selben Netz** wie Home Assistant) und **„Busch-Radio"** als Gerät wählen. + Beim ersten Mal meldet sich Soloist dabei mit deinem Konto an, danach bleibt die Anmeldung gespeichert. + +Der Schlüssel ist persönlich: nicht weitergeben, nicht in Logs oder Issues posten. +Mit der Nutzung von Soloist gelten die Nutzungsbedingungen von Spotify. Soloist ist **nicht** im Add-on enthalten +(Spotify erlaubt keine Weitergabe), sondern wird beim Start direkt von Spotify geladen. + +### 3b. Mit librespot (Rückfall, ohne API-Key) Beim **ersten Start** erscheint im Log: @@ -120,7 +144,7 @@ Dann unter **Einstellungen → Integrationen → Busch-Radio Spotify Bridge** ei | URL | Funktion | |---|---| -| `http://:5589` | Einrichtungs-Assistent (OAuth) | +| `http://:5589` | Einrichtungs-Assistent (OAuth, nur librespot) | | `http://:8000/stream` | Stream-URL für das Radio | | `http://:8000` | Icecast-Statusseite | @@ -132,23 +156,29 @@ Dann unter **Einstellungen → Integrationen → Busch-Radio Spotify Bridge** ei | Komponente | Funktion | |---|---| -| [librespot](https://github.com/librespot-org/librespot) main | Spotify Connect Client (PCM-Ausgabe via Pipe) | +| Spotify Soloist | Offizieller Spotify Connect Client, spielt in eine PipeWire-Senke (amd64/aarch64) | +| [PipeWire](https://pipewire.org) + WirePlumber | Virtuelle Senke `busch_radio`, `pw-record` greift sie als PCM ab | +| [librespot](https://github.com/librespot-org/librespot) main | Rückfall: Spotify Connect Client (PCM-Ausgabe via Pipe) | | [ffmpeg](https://ffmpeg.org) | PCM → MP3/AAC Transkodierung | | [Icecast](https://icecast.org) | HTTP-Stream-Server | ### Signalfluss ``` -Spotify CDN → librespot (dekodiert, PCM auf stdout) +Soloist: Spotify → Soloist → PipeWire-Senke "busch_radio" → pw-record (PCM auf stdout) +librespot: Spotify → librespot (dekodiert, PCM auf stdout) → silence-injector (hält Stream bei Pause aufrecht) - → ffmpeg -re (Echtzeit-Encoding → MP3/AAC) + → ffmpeg (Encoding → MP3/AAC; bei librespot mit -re für Echtzeit) → Icecast (HTTP-Stream) → Busch-Jäger Radio ``` ### Hinweise zum Build -- librespot wird aus dem Quellcode kompiliert (Rust, ~10–15 Min.) +- amd64/aarch64 nutzen ein Debian-Basisimage (Soloist braucht glibc ≥ 2.38), 32-Bit bleibt Alpine +- librespot wird aus dem Quellcode kompiliert (Rust, ~10–15 Min.), statisch gelinkt – läuft auf beiden Basisimages +- Soloist liegt in `/data/soloist/bin`; Builds laufen nach 90 Tagen ab, das Add-on lädt rechtzeitig neue + und wechselt, sobald gerade nichts spielt - Der OAuth-Callback-Server bindet an `0.0.0.0` statt `127.0.0.1`, damit der Browser-Login aus dem Heimnetz funktioniert - Credentials werden in `/data/librespot-cache/` persistent gespeichert @@ -158,7 +188,10 @@ Spotify CDN → librespot (dekodiert, PCM auf stdout) | Problem | Lösung | |---|---| -| „Busch-Radio" erscheint nicht in Spotify | Einrichtungs-Seite öffnen: `http://:5589` | +| Jeder Titel wird übersprungen, Log zeigt `error audio key 0 1` | Spotify verweigert librespot für dieses Konto → Soloist-API-Key eintragen (ab 1.1.0) | +| „Busch-Radio" erscheint nicht in Spotify (Soloist) | Handy im selben Netz wie HA? Im Log `Empfänger : soloist` und `Soloist wird gestartet` prüfen | +| `Soloist konnte nicht geladen werden` | Internetzugang von HA prüfen; das Add-on fällt solange auf librespot zurück | +| „Busch-Radio" erscheint nicht in Spotify (librespot) | Einrichtungs-Seite öffnen: `http://:5589` | | Stream nicht erreichbar | Icecast-Status prüfen: `http://:8000` | | Stream bricht bei Pause ab | Auf Version 1.0.11+ aktualisieren | | Songs wechseln zu schnell | Auf Version 1.0.10+ aktualisieren | @@ -172,12 +205,15 @@ Spotify CDN → librespot (dekodiert, PCM auf stdout) ``` busch-radio-spotify/ ├── busch_radio_spotify/ # Home Assistant Add-on -│ ├── Dockerfile # Multi-Stage Build (Rust + Alpine) +│ ├── Dockerfile # Multi-Stage Build (Rust → Debian bzw. Alpine) │ ├── config.yaml # Add-on Manifest & Optionen │ ├── build.yaml # Multi-Arch Konfiguration │ ├── DOCS.md # Add-on Dokumentation (in HA angezeigt) │ ├── run.sh # Startup-Script -│ ├── oauth_helper.py # OAuth-Einrichtungs-Assistent (Port 5589) +│ ├── oauth_helper.py # OAuth-Einrichtungs-Assistent (Port 5589, librespot) +│ ├── soloist-fetch.sh # Lädt/aktualisiert Spotify Soloist +│ ├── pipewire/ # PipeWire-Senke für Soloist +│ ├── wireplumber/ # WirePlumber ohne Hardware/D-Bus │ ├── icon.png # Add-on Icon (Store) │ └── logo.png # Add-on Logo (Detailseite) ├── custom_components/ # Optionale HA Integration @@ -195,7 +231,9 @@ busch-radio-spotify/ ## Rechtliche Hinweise -- Dieses Projekt nutzt **librespot**, eine Open-Source-Reimplementierung des Spotify-Clients +- **Spotify Soloist** ist Software von Spotify; sie wird nicht mit diesem Projekt verteilt, sondern direkt von Spotify geladen. + Dieses Projekt ist nicht mit Spotify verbunden. +- Als Rückfall nutzt das Projekt **librespot**, eine Open-Source-Reimplementierung des Spotify-Clients - Audio wird **nicht gespeichert** – ausschließlich live gestreamt - Ausschließlich für den **privaten Heimgebrauch** gedacht - **Spotify Premium** ist für Spotify Connect erforderlich diff --git a/busch_radio_spotify/CHANGELOG.md b/busch_radio_spotify/CHANGELOG.md index 1e938fa..1987cbb 100644 --- a/busch_radio_spotify/CHANGELOG.md +++ b/busch_radio_spotify/CHANGELOG.md @@ -1,5 +1,18 @@ # Änderungsprotokoll +## 1.1.0 + +- **Spotify Soloist** als neuer Empfänger: Spotifys offizieller Linux-Client ersetzt librespot, sobald + `soloist_api_key` gesetzt ist. Behebt „jeder Titel wird übersprungen“ (`error audio key 0 1`), weil Spotify + librespot bei vielen Konten keine Audio-Schlüssel mehr gibt +- Soloist wird beim Start von Spotify geladen (nicht im Image enthalten) und automatisch aktualisiert + (Builds laufen nach 90 Tagen ab); Audio läuft über eine PipeWire-Senke in die bestehende Icecast-Pipeline +- **librespot bleibt Rückfall**: ohne API-Key, auf 32-Bit-Geräten und wenn Soloist nicht geladen werden kann +- amd64/aarch64 nutzen jetzt ein Debian-Basisimage (Soloist braucht glibc); librespot statisch gelinkt +- **Build-Fix**: librespot hat die OAuth-Ausgabe umgebaut, der alte Patch griff nicht mehr und Neuinstallationen + brachen ab. librespot ist jetzt auf einen festen Commit (0.8.0, `99b6088`) gepinnt +- Dokumentation und README überarbeitet + ## 1.0.11 - **Pause-Fix**: Stream reißt bei Spotify-Pause nicht mehr ab – ein Silence-Injektor hält die Icecast-Verbindung aufrecht diff --git a/busch_radio_spotify/DOCS.md b/busch_radio_spotify/DOCS.md index aa8690e..4ea4f41 100644 --- a/busch_radio_spotify/DOCS.md +++ b/busch_radio_spotify/DOCS.md @@ -2,39 +2,37 @@ Streamt Spotify-Musik als Internetradio-Stream für das Busch-Jäger Unterputz-Internetradio. -Ein virtuelles Spotify Connect-Gerät (librespot) nimmt Audio entgegen und stellt es per Icecast als HTTP-Stream bereit. +Ein virtuelles Spotify Connect-Gerät nimmt Audio entgegen und stellt es per Icecast als HTTP-Stream bereit. +Empfänger ist **Spotify Soloist** (Spotifys offizieller Client); ohne API-Key oder auf 32-Bit-Geräten **librespot**. ``` -Spotify-App → librespot → ffmpeg → Icecast → Busch-Jäger Radio +Spotify-App → Soloist / librespot → ffmpeg → Icecast → Busch-Jäger Radio ``` --- -## Erste Einrichtung +## Erste Einrichtung mit Soloist (empfohlen) -### 1. Add-on konfigurieren und starten +1. Im [Spotify-for-Developers-Dashboard](https://developer.spotify.com/dashboard) mit dem **Premium-Konto** anmelden, + im Bereich **Soloist API Key** einen Schlüssel erzeugen. +2. Schlüssel in `soloist_api_key` eintragen, speichern und das Add-on starten. + Im Log steht dann `Empfänger : soloist`. Beim ersten Start lädt das Add-on Soloist von Spotify (ca. 14 MB). +3. Stream-URL im Radio eintragen: `http://:8000/stream` +4. In der Spotify-App (Handy **im selben Netz** wie Home Assistant) **„Busch-Radio"** als Gerät wählen. + Beim ersten Mal meldet sich Soloist dabei mit deinem Konto an; die Anmeldung bleibt gespeichert. -Passe die Optionen an (siehe unten) und starte das Add-on. +Der Schlüssel ist persönlich – nicht weitergeben und nicht in Logs posten. Es gelten die Nutzungsbedingungen von Spotify. +Soloist ist nicht im Add-on enthalten, sondern wird direkt von Spotify geladen. Builds laufen nach 90 Tagen ab; +das Add-on prüft alle 12 Stunden auf neue und wechselt, sobald gerade nichts spielt. -### 2. Spotify autorisieren (einmalig) +## Erste Einrichtung mit librespot (ohne API-Key) -Öffne den Einrichtungs-Assistenten im Browser: +1. `soloist_api_key` leer lassen und das Add-on starten. +2. Einrichtungs-Assistent öffnen: `http://:5589` – er führt durch die Spotify-Anmeldung (einmalig). +3. Stream-URL im Radio eintragen und **„Busch-Radio"** in der Spotify-App wählen. -``` -http://:5589 -``` - -Der Assistent führt dich Schritt für Schritt durch die Anmeldung. Die Credentials werden dauerhaft gespeichert – dieser Schritt ist nur beim ersten Start nötig. - -### 3. Stream-URL im Radio eintragen - -``` -http://:8000/stream -``` - -### 4. Musik abspielen - -Wähle in der Spotify-App **„Busch-Radio"** (oder deinen konfigurierten Gerätenamen) als Abspielgerät aus. +> Spotify verweigert librespot bei manchen Konten die Audio-Schlüssel. Dann wird jeder Titel übersprungen und +> im Log steht `error audio key 0 1`. In dem Fall hilft nur der Wechsel auf Soloist. --- @@ -48,6 +46,7 @@ Wähle in der Spotify-App **„Busch-Radio"** (oder deinen konfigurierten Gerät | `stream_port` | `8000` | HTTP-Port des Icecast-Streams | | `stream_mount` | `/stream` | URL-Pfad des Streams | | `icecast_password` | – | Internes Icecast-Passwort (bitte ändern) | +| `soloist_api_key` | leer | Soloist-API-Key; leer = librespot. Nur amd64/aarch64 | --- @@ -55,35 +54,36 @@ Wähle in der Spotify-App **„Busch-Radio"** (oder deinen konfigurierten Gerät | URL | Funktion | |---|---| -| `http://:5589` | Einrichtungs-Assistent (OAuth) | | `http://:8000/stream` | Stream-URL für das Radio | | `http://:8000` | Icecast-Statusseite | +| `http://:5589` | Einrichtungs-Assistent (nur librespot) | --- ## Fehlerbehebung +**Jeder Titel wird übersprungen, Log: `error audio key 0 1`** +→ Spotify verweigert librespot für dieses Konto. Soloist-API-Key eintragen (siehe oben). + **„Busch-Radio" erscheint nicht in der Spotify-App** -→ Spotify-Autorisierung noch nicht abgeschlossen. Einrichtungs-Seite öffnen: `http://:5589` +→ Soloist: Handy im selben WLAN wie Home Assistant? Im Log nach `Soloist wird gestartet` schauen. +→ librespot: Spotify-Autorisierung abschließen unter `http://:5589`. + +**`Soloist konnte nicht geladen werden – Rückfall auf librespot`** +→ Home Assistant erreicht Spotifys Server nicht (Internet/DNS prüfen). Nach Neustart wird es erneut versucht. **Stream nicht erreichbar** -→ Icecast-Statusseite prüfen: `http://:8000` -→ Port 8000 muss im Netzwerk erreichbar sein (`host_network: true` ist aktiviert) +→ Icecast-Statusseite prüfen: `http://:8000` (Port 8000 muss im Netzwerk erreichbar sein) -**Stream bricht bei Pause ab** -→ Add-on auf Version 1.0.11 oder neuer aktualisieren - -**Songs wechseln zu schnell / keine Steuerung vom Handy** -→ Add-on auf Version 1.0.10 oder neuer aktualisieren - -**Neu autorisieren** -→ Add-on stoppen → Datei `/data/librespot-cache/credentials.json` löschen → Add-on starten → Einrichtungs-Seite öffnen +**Neu anmelden** +→ Soloist: Add-on stoppen → Ordner `/data/soloist/data` löschen → starten → Gerät in der App erneut wählen +→ librespot: Add-on stoppen → `/data/librespot-cache/credentials.json` löschen → starten → Einrichtungs-Seite öffnen --- ## Technische Hinweise +- amd64/aarch64 laufen auf Debian (Soloist braucht glibc), 32-Bit auf Alpine (nur librespot) - librespot wird beim Build aus dem Quellcode kompiliert (Rust) – der erste Build dauert ca. 10–15 Minuten -- Der OAuth-Callback-Server bindet an `0.0.0.0`, damit er aus dem Heimnetz erreichbar ist - Audio wird nicht gespeichert – ausschließlich live gestreamt - Spotify Premium ist für Spotify Connect erforderlich diff --git a/busch_radio_spotify/Dockerfile b/busch_radio_spotify/Dockerfile index 52ab677..adcfc4c 100644 --- a/busch_radio_spotify/Dockerfile +++ b/busch_radio_spotify/Dockerfile @@ -12,7 +12,8 @@ RUN apk add --no-cache \ openssl-libs-static \ git -# Librespot vom aktuellen main-Branch klonen, patchen und kompilieren. +# Librespot auf festem Commit des dev-Branchs (2026-10-21) bauen, patchen und kompilieren. +# Fest gepinnt, weil Umbauten upstream sonst die Patches unbemerkt brechen (passiert im Nov. 2026). # # v0.7.0 hat Kompatibilitätsprobleme mit Spotifys aktuellem Backend: # Spotify liefert keine Audio-Datei-IDs mehr → alle Tracks "not available". @@ -22,12 +23,13 @@ RUN apk add --no-cache \ # 1. println! → eprintln! für "Browse to:"-URL (stdout geht sonst in ffmpeg-Pipe) # 2. OAuth-Callback-Server auf 0.0.0.0 binden (statt nur 127.0.0.1) # 3. Deutsche Erfolgs-Meldung nach OAuth -RUN git clone --depth 1 \ - https://github.com/librespot-org/librespot.git /build && \ - cd /build && \ +ARG LIBRESPOT_COMMIT=99b6088bf3ea028f90192676ac1a337fa4b2ed12 +RUN git init -q /build && cd /build && \ + git remote add origin https://github.com/librespot-org/librespot.git && \ + git fetch -q --depth 1 origin "${LIBRESPOT_COMMIT}" && git checkout -q FETCH_HEAD && \ # Patch 1: "Browse to:"-URL auf stderr statt stdout. sed -i \ - -e 's/println!("Browse to: {auth_url}")/eprintln!("Browse to: {auth_url}")/' \ + -e 's/println!("Browse to: /eprintln!("Browse to: /g' \ -e 's/println!("Provide redirect URL")/eprintln!("Provide redirect URL")/' \ oauth/src/lib.rs && \ grep -n "eprintln.*Browse to" oauth/src/lib.rs || { echo "FEHLER: println→eprintln Patch fehlgeschlagen!"; exit 1; } && \ @@ -37,7 +39,8 @@ RUN git clone --depth 1 \ -e 's/Go back to your terminal :)/Autorisierung erfolgreich! Du kannst diesen Tab schliessen./' \ oauth/src/lib.rs && \ grep -n "UNSPECIFIED" oauth/src/lib.rs || { echo "FEHLER: TcpListener-Patch fehlgeschlagen!"; exit 1; } && \ - cargo build \ + # OpenSSL statisch: das musl-Binary muss auch im Debian-Image laufen (kein musl-libssl dort) + OPENSSL_STATIC=1 cargo build \ --release \ --no-default-features \ --features "native-tls" && \ @@ -45,32 +48,43 @@ RUN git clone --depth 1 \ cp target/release/librespot /install/bin/librespot # ============================================================ -# Runtime stage: HA-Basis-Image + ffmpeg + icecast +# Runtime stage: HA-Basis-Image + ffmpeg + icecast (+ PipeWire für Soloist) # ============================================================ +# amd64/aarch64: Debian (glibc) – Spotify Soloist braucht glibc ≥ 2.38. +# armhf/armv7: Alpine – für 32-Bit gibt es kein Soloist, dort nur librespot. +# Das librespot-Binary aus dem musl-Build ist statisch gelinkt und läuft auf beiden. +# Soloist selbst steckt NICHT im Image (Spotify erlaubt keine Weitergabe), +# es wird beim Start von Spotify geladen (siehe soloist-fetch.sh). FROM ${BUILD_FROM} SHELL ["/bin/bash", "-o", "pipefail", "-c"] -# Abhängigkeiten installieren -# icecast liegt in Alpine's Community-Repository -RUN apk add --no-cache \ - bash \ - jq \ - curl \ - python3 \ - ffmpeg \ - && apk add --no-cache \ - --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community \ - icecast \ - || apk add --no-cache icecast +RUN if command -v apk >/dev/null; then \ + apk add --no-cache bash jq curl python3 ffmpeg \ + && { apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community icecast \ + || apk add --no-cache icecast; }; \ + else \ + apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + jq curl python3 ffmpeg icecast2 \ + pipewire pipewire-bin wireplumber libpipewire-0.3-modules libspa-0.2-modules \ + libpulse0 libatomic1 \ + && apt-get clean && rm -rf /var/lib/apt/lists/*; \ + fi # Librespot-Binary aus dem Build-Stage übernehmen COPY --from=librespot-builder /install/bin/librespot /usr/local/bin/librespot -RUN chmod +x /usr/local/bin/librespot +RUN chmod +x /usr/local/bin/librespot && librespot --version + +# PipeWire im Container: virtuelle Senke, die ffmpeg abgreift (nur Soloist) +ENV XDG_RUNTIME_DIR="/run/pipewire" +COPY pipewire/ /etc/pipewire/pipewire.conf.d/ +COPY wireplumber/ /etc/wireplumber/wireplumber.conf.d/ # Add-on Dateien kopieren COPY run.sh /run.sh COPY oauth_helper.py /oauth_helper.py -RUN chmod a+x /run.sh /oauth_helper.py +COPY soloist-fetch.sh /usr/local/bin/soloist-fetch +RUN chmod a+x /run.sh /oauth_helper.py /usr/local/bin/soloist-fetch CMD ["/run.sh"] diff --git a/busch_radio_spotify/build.yaml b/busch_radio_spotify/build.yaml index 09656c1..063c65f 100644 --- a/busch_radio_spotify/build.yaml +++ b/busch_radio_spotify/build.yaml @@ -1,9 +1,8 @@ --- # Multi-Architektur Build-Konfiguration für das HA Add-on. -# Jede Architektur bekommt das passende Alpine-basierte HA-Basisimage. +# amd64/aarch64 auf Debian (glibc, für Spotify Soloist), 32-Bit bleibt Alpine (nur librespot). build_from: - aarch64: ghcr.io/home-assistant/aarch64-base:latest - amd64: ghcr.io/home-assistant/amd64-base:latest + aarch64: ghcr.io/hassio-addons/debian-base:9.5.0 + amd64: ghcr.io/hassio-addons/debian-base:9.5.0 armhf: ghcr.io/home-assistant/armhf-base:latest armv7: ghcr.io/home-assistant/armv7-base:latest - diff --git a/busch_radio_spotify/config.yaml b/busch_radio_spotify/config.yaml index 67d94e3..8f03ca2 100644 --- a/busch_radio_spotify/config.yaml +++ b/busch_radio_spotify/config.yaml @@ -1,11 +1,11 @@ --- name: "Busch-Radio Spotify Bridge" -version: "1.0.11" +version: "1.1.0" slug: busch_radio_spotify description: > Streamt Spotify-Musik als Internet-Radio-Stream für das Busch-Jäger Unterputz-Internetradio. - Das Add-on erzeugt ein virtuelles Spotify Connect-Gerät (via librespot) und stellt das Audio - als MP3- oder AAC-Stream über Icecast bereit. + Das Add-on erzeugt ein virtuelles Spotify Connect-Gerät (Spotify Soloist, Rückfall librespot) + und stellt das Audio als MP3- oder AAC-Stream über Icecast bereit. url: "https://gitea.bitfire.work/retr0/Busch-Radio-Spotify" arch: - aarch64 @@ -27,6 +27,7 @@ options: stream_port: 8000 stream_mount: "/stream" icecast_password: "busch-radio-geheim" + soloist_api_key: "" schema: device_name: str @@ -35,6 +36,8 @@ schema: stream_port: port stream_mount: str icecast_password: str + # Leer → librespot. Gesetzt (nur amd64/aarch64) → Spotify Soloist. + soloist_api_key: password? # ---- UI ---- panel_icon: mdi:radio diff --git a/busch_radio_spotify/pipewire/10-busch-radio.conf b/busch_radio_spotify/pipewire/10-busch-radio.conf new file mode 100644 index 0000000..2a1837c --- /dev/null +++ b/busch_radio_spotify/pipewire/10-busch-radio.conf @@ -0,0 +1,25 @@ +# PipeWire im Add-on: eine virtuelle Senke "busch_radio". Soloist spielt dort +# hinein, pw-record greift den Monitor ab und reicht rohes PCM an ffmpeg weiter. +context.properties = { + default.clock.rate = 44100 + default.clock.allowed-rates = [ 44100 ] + # Kein D-Bus/rtkit im Container + support.dbus = false + module.rt = false +} + +context.objects = [ + { factory = adapter + args = { + factory.name = support.null-audio-sink + node.name = busch_radio + node.description = "Busch-Radio Stream" + media.class = Audio/Sink + audio.position = [ FL FR ] + audio.rate = 44100 + # Senke treibt den Graphen auch ohne Hardware-Takt + node.driver = true + priority.session = 2000 + } + } +] diff --git a/busch_radio_spotify/run.sh b/busch_radio_spotify/run.sh index 32bce86..bab9ba9 100644 --- a/busch_radio_spotify/run.sh +++ b/busch_radio_spotify/run.sh @@ -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 < nobody - nobody + ${NOBODY_GROUP} @@ -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="" fi -# ── OAuth-Hilfsserver starten ───────────────────────────────────────────────── -# Stellt unter http://: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://: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})..." diff --git a/busch_radio_spotify/soloist-fetch.sh b/busch_radio_spotify/soloist-fetch.sh new file mode 100644 index 0000000..5894967 --- /dev/null +++ b/busch_radio_spotify/soloist-fetch.sh @@ -0,0 +1,68 @@ +#!/command/with-contenv bashio +# ============================================================================== +# Lädt den offiziellen Spotify-Soloist-Build für diese Architektur. +# +# Spotify erlaubt keine Weitergabe von Soloist, deshalb steckt es nicht im Image, +# sondern wird von Spotifys CDN geholt und in /data/soloist/bin abgelegt. +# Builds laufen 90 Tage nach Veröffentlichung ab; über das ETag des Archivs +# wird ein neuerer Build erkannt. +# +# Aufruf: soloist-fetch [--stage] +# --stage neuen Build als soloist.new ablegen (wird beim nächsten Start übernommen) +# Exit: 0 = aktuell, 1 = Fehler, 2 = neuer Build installiert/abgelegt +# ============================================================================== +set -u +BIN_DIR="/data/soloist/bin" +ZIEL="soloist"; ETAG_DATEI=".etag" +if [ "${1:-}" = "--stage" ]; then ZIEL="soloist.new"; ETAG_DATEI=".etag.new"; fi + +case "$(uname -m)" in + aarch64) ARCH="arm64" ;; + x86_64) ARCH="x86_64" ;; + *) bashio::log.error "Soloist gibt es nicht für $(uname -m)"; exit 1 ;; +esac +URL="https://soloist-builds.spotifycdn.com/soloist_release_${ARCH}.tar.gz" +mkdir -p "${BIN_DIR}" + +etag() { tr -d '\r' | awk -F': ' 'tolower($1)=="etag" {print $2}' | tail -n 1; } + +REMOTE=$(curl -sfIL --max-time 30 "${URL}" | etag) || true +if [ -z "${REMOTE}" ]; then + bashio::log.warning "Spotify-CDN nicht erreichbar (${URL})" + exit 1 +fi +KENNUNG="${ARCH} ${REMOTE}" + +if [ -x "${BIN_DIR}/${ZIEL}" ] && [ "$(cat "${BIN_DIR}/${ETAG_DATEI}" 2>/dev/null)" = "${KENNUNG}" ]; then + exit 0 +fi +# Beim Vormerken: installierter Build ist schon der neueste → nichts tun +if [ "${ZIEL}" = "soloist.new" ] && [ "$(cat "${BIN_DIR}/.etag" 2>/dev/null)" = "${KENNUNG}" ]; then + exit 0 +fi + +bashio::log.info "Lade Spotify Soloist (${ARCH})..." +TMP=$(mktemp -d "${BIN_DIR}/.download.XXXXXX") +trap 'rm -rf "${TMP}"' EXIT + +if ! curl -sfL --max-time 600 -D "${TMP}/headers" -o "${TMP}/soloist.tar.gz" "${URL}"; then + bashio::log.error "Download fehlgeschlagen: ${URL}" + exit 1 +fi +KENNUNG="${ARCH} $(etag < "${TMP}/headers")" + +if ! tar -xzf "${TMP}/soloist.tar.gz" -C "${TMP}" soloist; then + bashio::log.error "Archiv enthält kein soloist-Programm" + exit 1 +fi +chmod 0755 "${TMP}/soloist" +if ! VERSION=$("${TMP}/soloist" --version 2>&1); then + bashio::log.error "Geladener Soloist-Build startet nicht (abgelaufen?): ${VERSION}" + exit 1 +fi + +mv -f "${TMP}/soloist" "${BIN_DIR}/${ZIEL}" +echo "${KENNUNG}" > "${BIN_DIR}/${ETAG_DATEI}" +if [ "${ZIEL}" = "soloist" ]; then rm -f "${BIN_DIR}/soloist.new" "${BIN_DIR}/.etag.new"; fi +bashio::log.info "Soloist bereit: ${VERSION//$'\n'/, }" +exit 2 diff --git a/busch_radio_spotify/wireplumber/10-busch-radio.conf b/busch_radio_spotify/wireplumber/10-busch-radio.conf new file mode 100644 index 0000000..fdf064d --- /dev/null +++ b/busch_radio_spotify/wireplumber/10-busch-radio.conf @@ -0,0 +1,15 @@ +# WirePlumber verbindet nur Soloist mit der virtuellen Senke. +# Keine Hardware, kein D-Bus, keine Benutzersitzung im Container. +override.context.modules = [ + { name = libpipewire-module-protocol-native } + { name = libpipewire-module-metadata } +] + +wireplumber.profiles = { + main-embedded = { + hardware.audio = disabled + hardware.bluetooth = disabled + hardware.video-capture = disabled + support.dbus = disabled + } +}