import json, re, time from pathlib import Path from notebooklm_tools.utils.cdp import _cdp_http_base, find_or_create_notebooklm_page_by_cdp_url, get_page_cookies, get_page_html from notebooklm_tools.core.auth import get_auth_manager cdp_http = _cdp_http_base(9223) page = find_or_create_notebooklm_page_by_cdp_url(cdp_http) ws_url = page.get("webSocketDebuggerUrl") raw_cookies = get_page_cookies(ws_url) html = get_page_html(ws_url) csrf_match = re.search(r'"SNlM0e":"([^"]+)"', html) csrf = csrf_match.group(1) if csrf_match else "" fdr_match = re.search(r'"FdrFJe":"(\d+)"', html) session_id = fdr_match.group(1) if fdr_match else "" bl_match = re.search(r'"cfb2h":"([^"]+)"', html) build_label = bl_match.group(1) if bl_match else "" print("Extracted CSRF:", csrf) print("Extracted Session ID:", session_id) print("Extracted Build Label:", build_label) print("Cookies count:", len(raw_cookies)) manager = get_auth_manager("default") manager.save_profile( cookies=raw_cookies, csrf_token=csrf, session_id=session_id, build_label=build_label, force=True ) print("Profile saved successfully!") storage = Path.home() / ".notebooklm-mcp-cli" with open(storage / "profiles" / "default" / "cookies.json") as f: cookies = json.load(f) payload = { "cookies": cookies, "csrf_token": csrf, "session_id": session_id, "build_label": build_label, "extracted_at": time.time() } with open(storage / "auth.json", "w") as f: json.dump(payload, f, indent=2) print("auth.json saved successfully!")