import json

har_path = r"c:\Users\Claud\Documents\ScriptNowTest\dazn\dz.har"
print("Caricamento HAR...")
with open(har_path, "r", encoding="utf-8", errors="ignore") as f:
    har = json.load(f)

entries = har.get("log", {}).get("entries", [])
print(f"Totale entries: {len(entries)}")

for entry in entries:
    url = entry.get("request", {}).get("url", "")
    if "license" in url.lower() or "widevine" in url.lower() or "drm" in url.lower():
        req = entry.get("request", {})
        resp = entry.get("response", {})
        print(f"\n{'='*80}")
        print(f"URL: {url}")
        print(f"Method: {req.get('method')}")
        print(f"Status: {resp.get('status')}")
        print("Request Headers:")
        for h in req.get("headers", []):
            name = h.get("name", "").lower()
            if name in ("authorization", "x-dazn-device", "x-daznid", "x-brand", "content-type", "x-correlation-id", "origin", "referer"):
                print(f"  {h['name']}: {h['value'][:100]}")
        print(f"Response status: {resp.get('status')} {resp.get('statusText')}")
