Add a live weather inset and local soundtrack support

This commit is contained in:
Josh
2026-11-13 15:08:36 -05:00
parent 1bfd720c81
commit ccec1e7044
7 changed files with 100 additions and 12 deletions

View File

@@ -36,7 +36,9 @@ The current host uses the NVIDIA Compose override for Tunarr's CUDA transcode pr
Tune to channel 99 in the retroLabs Roku app. This host is configured for Dunnellon, FL (34431). The screen rotates through current conditions, six hourly periods, six extended forecast periods, and sunrise/sunset. Active NWS alerts appear across the rotation. The bridge caches data and marks delayed responses.
To set a location on another host, set `RETROTV_WEATHER_POINT` (latitude,longitude) and `RETROTV_WEATHER_LOCATION` in `.env`, then run `docker compose up -d --no-deps bridge`. The bridge serves the feed at `/api/v1/weather`. Weather is rendered by the Roku app.
To set a location on another host, set `RETROTV_WEATHER_POINT` (latitude,longitude) and `RETROTV_WEATHER_LOCATION` in `.env`, then run `docker compose up -d --no-deps bridge`. The bridge serves the feed at `/api/v1/weather`. Weather is rendered by the Roku app. Its muted live inset shows the last tuned linear channel, or the first linear channel when weather is opened directly. The inset shares the tuner's video player.
To add background music, place a local MP3 at `data/weather/forecast.mp3` on the bridge host. The file is served over the LAN and loops while the weather channel is open. The directory is mounted read-only in the bridge and ignored by Git.
## Roku

View File

@@ -10,7 +10,7 @@ from xml.etree import ElementTree as XML
import httpx
from fastapi import FastAPI, HTTPException, Query, Request
from fastapi.responses import RedirectResponse, Response, StreamingResponse
from fastapi.responses import FileResponse, RedirectResponse, Response, StreamingResponse
from starlette.background import BackgroundTask
from .discovery import SERVICE, start_discovery
@@ -115,6 +115,7 @@ def create_app(*, tunarr_url=None, transport=None, discover=True, id_file=None):
base_url = f"http://{ip}:{port}"
name = os.getenv("RETROTV_NAME", "retroLabs")
weather_provider = NWSWeather()
weather_music = Path(os.getenv("RETROTV_WEATHER_MUSIC", "data/weather/forecast.mp3"))
upstream = tunarr_url or os.getenv("RETROTV_TUNARR_URL", "http://127.0.0.1:14242")
identity = Path(id_file or os.getenv("RETROTV_ID_FILE", "data/server-id"))
@@ -222,7 +223,14 @@ def create_app(*, tunarr_url=None, transport=None, discover=True, id_file=None):
@app.get("/api/v1/weather")
async def weather():
return await weather_provider.read()
data = await weather_provider.read()
return {**data, "musicUrl": "/api/v1/weather/music.mp3" if weather_music.is_file() else None}
@app.get("/api/v1/weather/music.mp3")
async def weather_audio():
if not weather_music.is_file():
raise HTTPException(404, "Weather music is not configured")
return FileResponse(weather_music, media_type="audio/mpeg")
async def proxy(request, path, *, playlist=False, params=None):
client = app.state.tunarr

View File

@@ -37,6 +37,7 @@ services:
RETROTV_WEATHER_LOCATION: ${RETROTV_WEATHER_LOCATION:-Local Weather}
volumes:
- bridge-data:/state
- ./data/weather:/app/data/weather:ro
volumes:
tunarr-data:

View File

@@ -46,6 +46,10 @@ sub onMenuSelect(event as object)
openGuide()
else if index = 1
m.channelIndex = -1
m.weather.visible = false
stopWeather()
m.videoChannelId = invalid
m.video.visible = false
m.video.control = "stop"
m.retryTimer.control = "stop"
loadLineup()

View File

@@ -27,6 +27,7 @@ sub findServer(baseUrl as string, useSaved as boolean)
m.weather.visible = false
stopWeather()
m.video.control = "stop"
m.videoChannelId = invalid
m.video.visible = false
m.playbackStatus.visible = false
m.retryTimer.control = "stop"
@@ -154,16 +155,26 @@ end sub
sub startPlayback()
if m.channelIndex < 0 then return
channel = m.channels[m.channelIndex]
m.video.control = "stop"
m.weather.visible = channel.type = "weather"
m.video.visible = not m.weather.visible
m.playbackStatus.visible = false
if m.weather.visible
startWeather()
return
end if
stopWeather()
m.video.visible = true
m.video.translation = [0, 0]
m.video.width = 1280
m.video.height = 720
m.video.mute = false
if m.videoChannelId = channel.id and m.video.state = "playing" then return
setPlaybackStatus("Tuning…")
playLinear(channel)
end sub
sub playLinear(channel as object)
m.video.control = "stop"
m.videoChannelId = invalid
streamUrl = channel.streamUrl
if GetInterface(streamUrl, "ifString") = invalid or streamUrl = ""
setPlaybackStatus("This channel has no stream.")
@@ -176,7 +187,7 @@ sub startPlayback()
content.live = true
content.title = channel.name
m.video.content = content
setPlaybackStatus("Tuning…")
m.videoChannelId = channel.id
m.video.control = "play"
end sub
@@ -278,7 +289,11 @@ sub setPlaybackStatus(message as string)
end sub
sub onVideoState()
if m.channelIndex < 0 or m.weather.visible then return
if m.weather.visible
if m.video.state = "error" or m.video.state = "finished" then hideWeatherPreview()
return
end if
if m.channelIndex < 0 then return
if m.video.state = "playing"
m.playbackStatus.visible = false
m.retryCount = 0
@@ -324,7 +339,7 @@ function onKeyEvent(key as string, press as boolean) as boolean
if m.previousIndex >= 0 then tune(m.previousIndex)
return true
else if LCase(key) = "ok"
if m.video.state = "error" or m.video.state = "finished"
if not m.weather.visible and (m.video.state = "error" or m.video.state = "finished")
tune(m.channelIndex)
else
showBanner()

View File

@@ -4,7 +4,7 @@
<script type="text/brightscript" uri="pkg:/components/Guide.brs" />
<script type="text/brightscript" uri="pkg:/components/Weather.brs" />
<children>
<Video id="video" width="1280" height="720" enableUI="false" />
<Audio id="weatherAudio" loop="true" />
<Group id="weather" visible="false">
<Rectangle width="1280" height="720" color="0x122D62FF" />
<Rectangle translation="[70,120]" width="1140" height="5" color="0x78E5EBFF" />
@@ -14,13 +14,18 @@
font="font:MediumBoldSystemFont" color="0x78E5EBFF" />
<Label id="weatherHeading" translation="[70,198]" width="1140" height="42"
font="font:MediumBoldSystemFont" />
<Label id="weatherBody" translation="[70,252]" width="1140" height="285"
font="font:MediumSystemFont" wrap="true" numLines="7" />
<Label id="weatherBody" translation="[70,252]" width="700" height="285"
font="font:SmallSystemFont" wrap="true" numLines="8" />
<Rectangle id="weatherPreviewFrame" translation="[800,208]" width="416" height="238"
color="0x78E5EBFF" visible="false" />
<Label id="weatherPreviewLabel" translation="[802,454]" width="412" height="70"
font="font:SmallBoldSystemFont" wrap="true" numLines="2" />
<Label id="weatherAlerts" translation="[70,553]" width="1140" height="74"
font="font:SmallBoldSystemFont" color="0xFFD57AFF" wrap="true" numLines="2" />
<Label id="weatherSource" translation="[70,646]" width="1140" height="32"
font="font:SmallSystemFont" color="0xB7D4E9FF" />
</Group>
<Video id="video" width="1280" height="720" enableUI="false" />
<Group id="banner" translation="[50,525]" visible="false">
<Rectangle width="1180" height="145" color="0x101A32EF" />
<Rectangle width="6" height="145" color="0x78E5EBFF" />

View File

@@ -1,5 +1,5 @@
sub initWeather()
for each id in ["weatherLocation", "weatherHeading", "weatherBody", "weatherAlerts", "weatherSource", "weatherRotation", "weatherRefresh"]
for each id in ["weatherLocation", "weatherHeading", "weatherBody", "weatherAlerts", "weatherSource", "weatherRotation", "weatherRefresh", "weatherAudio", "weatherPreviewFrame", "weatherPreviewLabel"]
m[id] = m.top.FindNode(id)
end for
m.weatherRotation.ObserveField("fire", "rotateWeather")
@@ -14,11 +14,51 @@ sub startWeather()
m.weatherBody.text = ""
m.weatherAlerts.text = ""
m.weatherSource.text = ""
startWeatherPreview()
refreshWeather()
m.weatherRefresh.control = "start"
end sub
sub startWeatherPreview()
preview = invalid
if m.previousIndex >= 0 and m.previousIndex < m.channels.Count()
candidate = m.channels[m.previousIndex]
if candidate.type = "linear" then preview = candidate
end if
if preview = invalid
for each candidate in m.channels
if candidate.type = "linear"
preview = candidate
exit for
end if
end for
end if
if preview = invalid
hideWeatherPreview()
return
end if
m.video.translation = [804, 212]
m.video.width = 408
m.video.height = 230
m.video.mute = true
m.video.visible = true
m.weatherPreviewFrame.visible = true
m.weatherPreviewLabel.text = "LIVE " + channelLabel(preview)
if m.videoChannelId <> preview.id or m.video.state <> "playing" then playLinear(preview)
end sub
sub hideWeatherPreview()
m.video.visible = false
m.video.control = "stop"
m.videoChannelId = invalid
m.weatherPreviewFrame.visible = false
m.weatherPreviewLabel.text = ""
end sub
sub stopWeather()
m.weatherAudio.control = "stop"
m.weatherMusicUrl = invalid
m.weatherRotation.control = "stop"
m.weatherRefresh.control = "stop"
if m.weatherWorker <> invalid
@@ -38,6 +78,7 @@ sub onWeather(event as object)
if not m.weather.visible then return
firstResult = m.weatherData = invalid
m.weatherData = event.GetData().data
if m.weatherData <> invalid then updateWeatherMusic(m.weatherData.musicUrl)
renderWeather()
if firstResult then m.weatherRotation.control = "start"
end sub
@@ -109,3 +150,15 @@ function tempLabel(value as dynamic) as string
if value = invalid then return "—"
return StrI(value).Trim() + "°F"
end function
sub updateWeatherMusic(path as dynamic)
if path = m.weatherMusicUrl then return
m.weatherAudio.control = "stop"
m.weatherMusicUrl = path
if GetInterface(path, "ifString") = invalid or path = "" then return
track = CreateObject("roSGNode", "ContentNode")
track.url = m.server.baseUrl + path
track.streamFormat = "mp3"
m.weatherAudio.content = track
m.weatherAudio.control = "play"
end sub