fix mediamtx client

This commit is contained in:
2026-04-28 21:58:13 +07:00
parent 8ad28090eb
commit 185b75087d
+22 -2
View File
@@ -31,8 +31,28 @@ class MediaMTXClient:
json=payload,
auth=self._auth(),
)
r.raise_for_status()
return r.json()
if r.status_code != 404:
r.raise_for_status()
return r.json()
# Backward-compatible fallback for MediaMTX versions that don't support bulk patch.
results: dict[str, Any] = {"fallback": []}
async with httpx.AsyncClient(timeout=10) as client:
for name in names:
rr = await client.patch(
f"{self.api_url}/v3/config/paths/patch/{name}",
json={"record": enabled},
auth=self._auth(),
)
if rr.status_code == 404:
rr = await client.post(
f"{self.api_url}/v3/config/paths/add/{name}",
json={"record": enabled},
auth=self._auth(),
)
rr.raise_for_status()
results["fallback"].append({"name": name, "status": rr.status_code})
return results
async def upsert_paths_sources_bulk(self, sources: dict[str, str]) -> dict[str, Any]:
payload = {"paths": {name: {"source": url} for name, url in sources.items()}}