fix mp4 compatibility issues

This commit is contained in:
zaiun xu
2026-04-10 18:16:15 +08:00
parent 09736f9e15
commit 62bff77fa0
15 changed files with 748 additions and 98 deletions

View File

@@ -40,12 +40,14 @@ def _should_log(resp: httpx.Response, body: Any) -> bool:
return resp.headers.get("X-Fish-Biomass-New", "").strip() == "1"
async def poll_once(client: httpx.AsyncClient, base: str) -> None:
async def poll_once(
client: httpx.AsyncClient, base: str, extra_headers: dict[str, str]
) -> None:
base = base.rstrip("/")
camera_url = f"{base}/api/v1/biomass/real/camera/"
health_url = f"{base}/api/v1/biomass/health/result/"
r1 = await client.get(camera_url)
r2 = await client.get(health_url)
r1 = await client.get(camera_url, headers=extra_headers)
r2 = await client.get(health_url, headers=extra_headers)
b1 = _fmt_body(r1)
b2 = _fmt_body(r2)
if _should_log(r1, b1):
@@ -54,11 +56,13 @@ async def poll_once(client: httpx.AsyncClient, base: str) -> None:
logger.info("[health/result/] HTTP {} | {}", r2.status_code, json.dumps(b2, ensure_ascii=False))
async def poll_loop(base: str, interval: float) -> None:
async def poll_loop(
base: str, interval: float, extra_headers: dict[str, str]
) -> None:
async with httpx.AsyncClient(timeout=30.0) as client:
while True:
try:
await poll_once(client, base)
await poll_once(client, base, extra_headers)
except Exception:
logger.exception("poll round failed")
await asyncio.sleep(max(interval, 0.5))
@@ -77,6 +81,11 @@ def main() -> None:
default=float(os.environ.get("POLL_INTERVAL", "5")),
help="轮询间隔秒数(默认 POLL_INTERVAL 或 5",
)
parser.add_argument(
"--client-id",
default=os.environ.get("BIOMASS_CLIENT_ID", "").strip() or None,
help="传给 X-Fish-Client-Id默认 BIOMASS_CLIENT_ID不设则与网关 default 游标一致)",
)
args = parser.parse_args()
logger.remove()
@@ -87,12 +96,16 @@ def main() -> None:
"<level>{level: <8}</level> | "
"<level>{message}</level>",
)
extra: dict[str, str] = {}
if args.client_id:
extra["X-Fish-Client-Id"] = args.client_id
logger.info(
"biomass_poller 启动 | base={} | interval={}s | GET /api/v1/biomass/real/camera/ 与 /health/result/",
"biomass_poller 启动 | base={} | interval={}s | client_id={} | GET biomass real/camera + health/result",
args.base_url.rstrip("/"),
args.interval,
args.client_id or "(default)",
)
asyncio.run(poll_loop(args.base_url, args.interval))
asyncio.run(poll_loop(args.base_url, args.interval, extra))
if __name__ == "__main__":