diff --git a/subwave_nowplaying.star b/subwave_nowplaying.star index aa16110..7986320 100644 --- a/subwave_nowplaying.star +++ b/subwave_nowplaying.star @@ -196,6 +196,14 @@ def main(config): if not now["online"]: return render.Root(child = _with_background(_message_screen([now["station"], "offline"], colors), colors)) + # A show's own theme override (if any) wins over the user's configured + # color_scheme, mirroring what SUB/WAVE's own web UI does -- see + # _fetch_show_theme. Falls back to the configured scheme on a fetch + # failure or an id this app doesn't recognize, rather than erroring. + show_theme_id = _fetch_show_theme(station_url) + if show_theme_id != None and show_theme_id in COLOR_SCHEMES: + colors = COLOR_SCHEMES[show_theme_id] + art = _fetch_cover(station_url, now["subsonic_id"]) progress = _track_progress(now["subsonic_id"], now["duration"]) @@ -958,6 +966,28 @@ def _format_time_temp(clock, weather): return " ยท ".join(parts) +def _fetch_show_theme(station_url): + # SUB/WAVE lets a show override the station's default color theme + # (controller/src/routes/public.ts resolves this server-side already: + # activeShow?.themeId || station default). That resolved value rides + # on /api/state's theme.active, not /api/now-playing -- a separate + # fetch, not a field on the response this app already pulls. + # + # Theme ids there use hyphens (e.g. "classic-light"), this app's + # COLOR_SCHEMES keys use underscores ("classic_light") -- same 8 + # names otherwise (confirmed against SUB/WAVE's own theme registry), + # so swapping the separator is enough to look it up directly rather + # than needing an explicit id-mapping table. + rep = http.get(station_url + "/api/state", ttl_seconds = NOWPLAYING_TTL) + if rep.status_code != 200: + return None + + theme_id = (rep.json().get("theme", {}) or {}).get("active", "") + if not theme_id: + return None + + return theme_id.replace("-", "_") + def _fetch_cover(station_url, subsonic_id): if not subsonic_id: return None