cameras: Live-Environment-Streams + HLS.js player
All checks were successful
build-and-deploy / build (push) Successful in 3m8s

Ingest ~4.2k direct HLS/YouTube feeds (VDOT, MDSHA, DelDOT, Iowa DOT,
OpenCCTV, etc.) from the public GeoJSON catalog. Popup plays HLS via a
CORS-safe playlist proxy + vendored hls.js, YouTube via embed, with
ffmpeg-MJPEG fallback. ALERTWest rows now use a stable camera id so
hourly scrapes do not duplicate.
This commit is contained in:
Sirius DevOps 2026-08-27 15:54:54 -04:00
commit 0c7f80655e
8 changed files with 263 additions and 14 deletions

View file

@ -812,10 +812,13 @@ async def camera_stream(camera_id: UUID):
if not row:
raise HTTPException(404, "Camera not found")
url = row["snapshot_url"] or row["source_url"]
if str(url or "").lower().startswith("rtsp://"):
low = str(url or "").lower()
if low.startswith("rtsp://") or ".m3u8" in low or row.get("device_type") == "hls":
from camera_preview import ffmpeg_mjpeg_stream, _FFMPEG
if not _FFMPEG:
raise HTTPException(502, "RTSP preview requires ffmpeg")
raise HTTPException(502, "Live preview requires ffmpeg")
if not low.startswith("rtsp://") and not low.startswith(("http://", "https://")):
raise HTTPException(404, "Camera or snapshot not found")
return StreamingResponse(
ffmpeg_mjpeg_stream(url),
media_type="multipart/x-mixed-replace; boundary=ffmpeg",
@ -858,6 +861,39 @@ async def camera_stream(camera_id: UUID):
return StreamingResponse(gen(), media_type=media)
@app.get("/api/cameras/{camera_id}/hls.m3u8")
async def camera_hls_playlist(camera_id: UUID):
"""CORS-safe rewritten HLS playlist for the in-page player."""
from camera_hls import fetch_playlist
from camera_models import cameras as cam_table
async with async_session() as session:
row = (await session.execute(
select(cam_table).where(cam_table.c.id == camera_id)
)).mappings().one_or_none()
if not row:
raise HTTPException(404, "Camera not found")
url = row["snapshot_url"] or row["source_url"] or ""
if ".m3u8" not in url.lower() and row.get("device_type") != "hls":
raise HTTPException(404, "Camera is not an HLS feed")
return await fetch_playlist(str(camera_id), url)
@app.get("/api/cameras/{camera_id}/hlsseg")
async def camera_hls_segment(camera_id: UUID, u: str = Query(..., min_length=8)):
"""Proxy one HLS segment/playlist URI rewritten by hls.m3u8."""
from camera_hls import fetch_segment
from camera_models import cameras as cam_table
async with async_session() as session:
exists = (await session.execute(
select(cam_table.c.id).where(cam_table.c.id == camera_id)
)).scalar_one_or_none()
if not exists:
raise HTTPException(404, "Camera not found")
return await fetch_segment(str(camera_id), u)
# ── News pipeline (scraper + summarizer) ──────────────────────────────────
# Backing data for the frontend news panel. Written by the vendored
# news-scraper (hourly Scrapy crawl) and news-summarizer (hourly Gemini