Add the Python `ingest` container exposing `GET /next`, which returns the next track as an annotated Liquidsoap URI (or an empty body when nothing is ready). Liquidsoap switches from a static playlist to a `request.dynamic` source pulling from the daemon, with the local cache as fallback and mksafe for guaranteed continuous output. For now the daemon just cycles through the files already in the cache; the download providers (Navidrome, yt-dlp, ListenBrainz) come in later milestones. Also commit the implementation plan (PLAN.md). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
51 lines
1.8 KiB
Text
51 lines
1.8 KiB
Text
#!/usr/bin/liquidsoap
|
|
|
|
# radieo — couche diffusion (jalon 2)
|
|
# La source principale est pilotée par le daemon d'ingestion via GET /next.
|
|
# Le dossier /cache sert de secours quand le daemon n'a rien à proposer
|
|
# (daemon indisponible, file momentanément vide…). Si tout est vide : silence.
|
|
|
|
# --- Journalisation : tout sur la sortie standard (pratique en conteneur) ---
|
|
settings.log.stdout := true
|
|
settings.log.file := false
|
|
settings.log.level := 3
|
|
|
|
# --- Harbor : écoute sur toutes les interfaces du conteneur ---
|
|
settings.harbor.bind_addrs := ["0.0.0.0"]
|
|
|
|
# URL du daemon d'ingestion (nom de service résolu par docker-compose).
|
|
ingest_url = "http://ingest:8080/next"
|
|
|
|
# Callback appelé par request.dynamic pour obtenir le prochain morceau.
|
|
# Renvoie une requête à jouer, ou null() si rien n'est disponible (→ secours).
|
|
def next_track() =
|
|
resp = http.get(ingest_url, timeout=5.0)
|
|
body = string.trim(resp)
|
|
if resp.status_code == 200 and body != "" then
|
|
request.create(body)
|
|
else
|
|
null
|
|
end
|
|
end
|
|
|
|
# Source principale : pilotée par le daemon. prefetch=1 pour anticiper le
|
|
# prochain morceau ; retry_delay pour ne pas marteler le daemon en cas de vide.
|
|
main = request.dynamic(next_track, prefetch=1, retry_delay=1.0)
|
|
|
|
# Secours : le cache local, joué en aléatoire, rechargé quand il change.
|
|
backup = playlist(mode="randomize", reload_mode="watch", "/cache")
|
|
|
|
# fallback préfère la source principale et bascule sur le cache si elle n'a
|
|
# rien de prêt. track_sensitive=true : on ne coupe pas un morceau en cours.
|
|
radio = fallback(track_sensitive=true, [main, backup])
|
|
|
|
# mksafe garantit un flux continu : silence plutôt que plantage si tout est vide.
|
|
radio = mksafe(radio)
|
|
|
|
# --- Sortie : flux MP3 sur http://<hote>:8000/radio.mp3 ---
|
|
output.harbor(
|
|
%mp3(bitrate=192),
|
|
port=8000,
|
|
mount="radio.mp3",
|
|
radio
|
|
)
|