"""confere.py — abre a parte no Chromium e lista os avisos do kit (palavra diferente da fala, fala que acabou, linha larga,
linha fora de ordem, filme sem índice, emoji não achado) + erros de JS, eventos e trechos de vídeo com som.
  python comp-a/confere.py parte1.html            python comp-a/confere.py "parte1.html?ate=60"
"""
import sys
from pathlib import Path
from playwright.sync_api import sync_playwright
sys.stdout.reconfigure(encoding="utf-8")
arg = sys.argv[1] if len(sys.argv) > 1 else "parte1.html"
path, _, q = arg.partition("?")
p = Path(path) if Path(path).exists() else Path(__file__).parent / path
with sync_playwright() as pw:
    b = pw.chromium.launch(); pg = b.new_page(viewport={"width": 1080, "height": 1920})
    msgs = []; pg.on("console", lambda m: msgs.append(f"{m.type}: {m.text}") if m.type in ("warning", "error") else None)
    pg.on("pageerror", lambda e: msgs.append(f"ERRO JS: {e}"))
    pg.goto(p.resolve().as_uri() + ("?" + q if q else "")); pg.wait_for_function("window.__ready", timeout=120000); pg.evaluate("window.__ready")
    ev = pg.evaluate("window.__events()")
    print(f"dur {ev['dur']:.1f} s · {len(ev['events'])} eventos · {len(ev['videos'])} trechos de vídeo com som")
    for v in ev["videos"]: print(f"  vídeo {v['nome']}: {v['t0']:.2f}–{v['t1']:.2f} s, trilha {v['trilha']}, alvo {v['alvo']}")
    print("\n".join(msgs) or "sem avisos"); b.close()
