Add spotify queue
Deploy HEOS panel / deploy (push) Successful in 30s

This commit is contained in:
franzz committed 2026-10-20 15:44:56 +02:00
1 parent 6c76121863
commit 6bee9bd9a3
13 files changed
+230 -5

No files matched your search

+36
View File
@@ -314,6 +314,25 @@ def _mark_spotify_accounts(rooms: list):
room["spotify_account"] = playing_on.get(_spotify_name(room["key"]))
# How much of a room's Spotify queue its card unfolds to.
QUEUE_LENGTH = 10
def _queue_item(item: dict) -> dict:
"""One queue entry in the same shape as a card's now-playing: a track
names its artists and its album's cover, a podcast episode its show."""
show = item.get("show") or {}
artist = ", ".join(a["name"] for a in item.get("artists") or [] if a.get("name")) or show.get("name")
images = (item.get("album") or {}).get("images") or item.get("images") or show.get("images") or []
# Spotify lists them widest first: the smallest still sharp on a retina phone, rather than a 640px cover squeezed into a thumbnail
sharp = [i for i in images if (i.get("width") or 0) >= 120]
image = (sharp[-1] if sharp else images[0] if images else {}).get("url")
return {
"song": item.get("name") or "",
"artist": artist or "",
"image": image,
"duration_ms": item.get("duration_ms")
}
def _link_zidoo_poster(avr: dict):
"""Point the AVR's now-playing cover at our own copy of the Zidoo's
poster: the panel is served over https, and the Zidoo only speaks plain
@@ -522,6 +541,23 @@ def api_spotify_devices():
return jsonify(_spotify_from(request.args).devices())
@app.get("/api/spotify/queue")
@handle_errors
def api_spotify_queue():
"""What comes next in a room's Spotify stream (?target=lego_room), asked
of whichever of your accounts is playing there. Only fetched when a card
unfolds its queue, not on every poll."""
key = _target_from(request.args)
# Demo rooms are not on anyone's real Spotify, so they bring their own queue.
if _is_demo():
return jsonify({"target": key, "queue": controller.spotify_queue(key)[:QUEUE_LENGTH]})
account = _spotify_playing_on().get(_spotify_name(key))
if account is None:
raise ValueError("Only a Spotify stream one of your accounts is playing has a queue to show")
items = spotify[account].queue()[:QUEUE_LENGTH]
return jsonify({"target": key, "account": account, "queue": [_queue_item(i) for i in items]})
@app.post("/api/spotify/resume")
@handle_errors
def api_spotify_resume():