cameras: Live-Environment-Streams + HLS.js player
All checks were successful
build-and-deploy / build (push) Successful in 3m8s
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:
parent
f3c35c2230
commit
0c7f80655e
8 changed files with 263 additions and 14 deletions
|
|
@ -303,6 +303,8 @@ def parse_alertwest_json(text: str, source_name: str) -> list[dict]:
|
|||
f"https://img.cdn.prod.alertwest.com/data/img/"
|
||||
f"{cid}/{dt:%Y}/{dt:%m}/{dt:%d}/{img}"
|
||||
)
|
||||
# Stable identity (the JPEG filename changes every capture).
|
||||
ident = f"https://img.cdn.prod.alertwest.com/cam/{cid}"
|
||||
loc = locs.get(cam.get("lid")) or {}
|
||||
try:
|
||||
lat = float(loc["lat"]) if loc.get("lat") is not None else None
|
||||
|
|
@ -312,7 +314,7 @@ def parse_alertwest_json(text: str, source_name: str) -> list[dict]:
|
|||
bits = [cam.get("cn"), cam.get("co"), loc.get("st") or cam.get("st")]
|
||||
name = ", ".join(str(b) for b in bits if b)
|
||||
out.append({
|
||||
"source_url": snap,
|
||||
"source_url": ident,
|
||||
"snapshot_url": snap,
|
||||
"discovery_source": source_name,
|
||||
"location_lat": lat,
|
||||
|
|
@ -324,6 +326,49 @@ def parse_alertwest_json(text: str, source_name: str) -> list[dict]:
|
|||
return out
|
||||
|
||||
|
||||
def parse_live_streams_geojson(text: str, source_name: str) -> list[dict]:
|
||||
"""Parse willytop8/Live-Environment-Streams GeoJSON.
|
||||
|
||||
Only direct, playable URLs: HLS, YouTube, HTTP stills. Skip html_page
|
||||
feeds that need token extraction or a headless browser.
|
||||
"""
|
||||
try:
|
||||
payload = json.loads(text)
|
||||
except (json.JSONDecodeError, ValueError):
|
||||
return []
|
||||
usable = {"hls", "youtube", "http_image"}
|
||||
out: list[dict] = []
|
||||
for feat in payload.get("features") or []:
|
||||
props = feat.get("properties") or {}
|
||||
ut = (props.get("url_type") or "").lower()
|
||||
if ut not in usable:
|
||||
continue
|
||||
if props.get("source_url_requires"):
|
||||
continue
|
||||
url = (props.get("url") or "").strip()
|
||||
if not url:
|
||||
continue
|
||||
coords = (feat.get("geometry") or {}).get("coordinates") or []
|
||||
lon = lat = None
|
||||
if len(coords) >= 2:
|
||||
try:
|
||||
lon, lat = float(coords[0]), float(coords[1])
|
||||
except (TypeError, ValueError):
|
||||
lon = lat = None
|
||||
dtype = "ip-cam" if ut == "http_image" else ut
|
||||
out.append({
|
||||
"source_url": url,
|
||||
"snapshot_url": url,
|
||||
"discovery_source": source_name,
|
||||
"location_lat": lat,
|
||||
"location_lon": lon,
|
||||
"location_name": props.get("display_name") or props.get("name"),
|
||||
"vendor": props.get("source_family"),
|
||||
"device_type": dtype,
|
||||
})
|
||||
return out
|
||||
|
||||
|
||||
def parse_directory_html(html: str, base_url: str, source_name: str) -> list[dict]:
|
||||
"""Generic Insecam-style directory parser."""
|
||||
cams = []
|
||||
|
|
@ -393,6 +438,9 @@ async def scrape_source(client: RateLimitedClient, geo: Geocoder,
|
|||
if ("getCameraDataByLoc" in src_url
|
||||
or ("json" in ctype and '"locs"' in body[:4000] and '"cams"' in body[:8000])):
|
||||
cams = parse_alertwest_json(body, name)
|
||||
elif (src_url.endswith(".geojson") or src_url.endswith("/streams.geojson")
|
||||
or '"FeatureCollection"' in body[:400]):
|
||||
cams = parse_live_streams_geojson(body, name)
|
||||
elif "html" in ctype:
|
||||
cams = parse_directory_html(body, str(resp.url), name)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in a new issue