Add a live weather inset and local soundtrack support
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user