stream: show a history of aired tracks (/history)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
a468d78153
commit
7fc372f18d
2 changed files with 62 additions and 4 deletions
|
|
@ -81,9 +81,24 @@ radio = crossfade(duration=3.0, fade_in=3.0, fade_out=3.0, radio)
|
|||
radio = mksafe(radio)
|
||||
|
||||
# --- Métadonnées « en cours de lecture » -----------------------------------
|
||||
# On mémorise les dernières métadonnées vues sur le flux réellement diffusé.
|
||||
# On mémorise les dernières métadonnées vues sur le flux réellement diffusé,
|
||||
# ainsi qu'un historique borné des titres passés à l'antenne (le plus récent
|
||||
# en tête). L'historique reflète ce qui a vraiment été diffusé.
|
||||
now_playing = ref([])
|
||||
radio.on_metadata(synchronous=false, fun(m) -> now_playing := m)
|
||||
history = ref([])
|
||||
history_max = 25
|
||||
radio.on_metadata(
|
||||
synchronous=false,
|
||||
fun(m) -> begin
|
||||
now_playing := m
|
||||
entry = {title=m["title"], artist=m["artist"]}
|
||||
head = list.hd(default={title="", artist=""}, history())
|
||||
is_dup = head.title == entry.title and head.artist == entry.artist
|
||||
if not is_dup and (entry.title != "" or entry.artist != "") then
|
||||
history := list.prefix(history_max, list.add(entry, history()))
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
# --- Sortie : flux MP3 sur http://<hote>:8000/radio.mp3 ---
|
||||
output.harbor(
|
||||
|
|
@ -112,6 +127,12 @@ harbor.http.register(
|
|||
end
|
||||
)
|
||||
|
||||
# Historique des titres passés (le plus récent en tête, morceau courant inclus).
|
||||
harbor.http.register(
|
||||
port=8000, method="GET", "/history",
|
||||
fun(_, resp) -> resp.json(history())
|
||||
)
|
||||
|
||||
# Passer au morceau suivant : on saute le morceau en cours sur la source
|
||||
# diffusée. request.dynamic a déjà préchargé le suivant, donc l'enchaînement
|
||||
# est immédiat (le prochain /next est demandé au daemon dans la foulée).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue