Skip to content

teng-lin/notebooklm-py

notebooklm

Verified

Install, authenticate, troubleshoot, and operate Gemini Notebook through the notebooklm-py CLI or typed async Python API. Use for notebook and source management, grounded chat and research, and artifact generation or download when the user mentions Gemini Notebook, notebooklm-py, the notebooklm CLI, or its Python API. Do not use for the generic Gemini API or unrelated content creation.

FileKindSize
SKILL.mdskill md16.0 KB
examples/bulk-import.pyscript3.4 KB
examples/chat.pyscript6.9 KB
examples/notes.pyscript9.8 KB
examples/quickstart.pyscript2.3 KB
examples/refresh_browser_cookies.pyscript2.9 KB
examples/research-to-podcast.pyscript3.2 KB
examples/video.pyscript5.9 KB
scripts/__init__.pyscript73 B
scripts/_ci_e2e_notebooks.pyscript19.0 KB
scripts/_ci_progress.pyscript2.5 KB
scripts/_ci_rpc_progress.pyscript7.5 KB
scripts/_live_auth_scenarios/__init__.pyscript2.6 KB
scripts/_live_auth_scenarios/_contract.pyscript1.9 KB
scripts/_live_auth_scenarios/browser_refresh.pyscript3.1 KB
scripts/_live_auth_scenarios/crash_safe_writer.pyscript1.9 KB
scripts/_live_auth_scenarios/master_token_recovery.pyscript3.3 KB
scripts/_live_auth_scenarios/mcp_recovery.pyscript3.0 KB
scripts/_live_auth_scenarios/rest_recovery.pyscript5.9 KB
scripts/_live_auth_scenarios/sibling_concurrent_reload.pyscript3.9 KB
scripts/_live_auth_scenarios/storage_reload.pyscript2.9 KB
scripts/_onetime_rescrub_cookies.pyscript6.6 KB
scripts/_onetime_retarget_cassette_hosts.pyscript8.5 KB
scripts/_strip_audit_refs.pyscript15.9 KB
scripts/_tracked_files.pyscript872 B
scripts/aggregate_ci_e2e_outcomes.pyscript10.8 KB
scripts/android_grpc_canary.pyscript26.6 KB
scripts/api-compat-allowlist.jsonconfig163 B
scripts/audit_auth_import_graph.pyscript7.5 KB
scripts/audit_auth_patch_sites.pyscript83.6 KB
scripts/audit_auth_shared_mutations.pyscript41.7 KB
scripts/audit_backend_coupling.pyscript32.8 KB
scripts/audit_public_api_compat.pyscript47.4 KB
scripts/audit_test_suite.pyscript10.7 KB
scripts/capture_mobile_grpc.jsscript5.1 KB
scripts/capture_rpc_registry.pyscript44.5 KB
scripts/check_action_pinning.pyscript6.7 KB
scripts/check_auth_behavior_scenario_policy.pyscript37.1 KB
scripts/check_auth_coverage_delta.pyscript23.2 KB
scripts/check_auth_lifecycle_cleanup_policy.pyscript11.7 KB
scripts/check_base_wheel.pyscript6.3 KB
scripts/check_ci_install_parity.pyscript8.8 KB
scripts/check_claude_md_freshness.pyscript8.0 KB
scripts/check_coverage_thresholds.pyscript8.4 KB
scripts/check_deprecation_targets.pyscript33.1 KB
scripts/check_docs_module_refs.pyscript14.4 KB
scripts/check_rpc_health.pyscript112.0 KB
scripts/check_workflow_permissions.pyscript5.3 KB
scripts/check_workflow_secret_gates.pyscript40.4 KB
scripts/decode_mobile_grpc.pyscript7.2 KB
scripts/diagnose_get_notebook.pyscript9.1 KB
scripts/extract_blutter_grpc_signatures.pyscript7.6 KB
scripts/live_auth_matrix.pyscript40.2 KB
scripts/manage_ci_e2e_notebooks.pyscript67.4 KB
scripts/materialize_ci_auth.pyscript8.0 KB
scripts/mcp_live_smoke.pyexecutablescript224 B
scripts/parse_pbenums.pyscript8.6 KB
scripts/parse_pbschema.pyscript11.8 KB
scripts/regen_baselines.pyscript2.7 KB
scripts/regenerate_android_protos.pyscript16.3 KB
scripts/rescrub-cassettes.pyscript13.3 KB
scripts/scrub_rpc_har.pyscript9.4 KB
scripts/select_ci_account.pyscript4.8 KB
scripts/stress_fault_server.pyscript20.6 KB
scripts/test_taxonomy_inventory.pyscript16.1 KB
scripts/verify_ci_artifacts.pyscript35.3 KB

scripts/decode_mobile_grpc.py

View on GitHub
#!/usr/bin/env python3
"""Recover NotebookLM Android gRPC message *shapes* from captured protobuf bodies.

Companion to ``scripts/capture_mobile_grpc.js`` and
``docs/android/capture.md``. Reads the ``.pb`` files a capture session wrote
(gRPC envelope already stripped) and prints a merged schema per method+direction:
field number, wire type, whether it repeats, and — for length-delimited fields —
whether the payload is a nested message, a string, or opaque bytes.

Privacy: string/bytes *values* are never printed, only their length. Varint and
fixed32/64 values ARE printed because they are flags, enums, page sizes, and
``google.protobuf.Timestamp`` seconds/nanos — not private text. Even so, do not
commit this tool's output verbatim; summarise shapes in docs instead (see
``docs/android/endpoints.md``).

Usage:
    python scripts/decode_mobile_grpc.py <capture-dir> [method-substring]

The wire format is walked with a hand-rolled varint reader so the script has no
third-party dependency (the project does not ship protobuf). Length-delimited
payloads are speculatively parsed as nested messages; this over-eagerly parses
UTF-8 text that happens to be valid wire format, so treat very deep trees under
free-text fields (chat turns, source/artifact content) as approximate.
"""

from __future__ import annotations

import collections
import glob
import os
import struct
import sys

WIRE = {0: "varint", 1: "i64", 2: "len", 5: "i32"}


def read_varint(b: bytes, i: int) -> tuple[int, int]:
    shift = 0
    val = 0
    while True:
        if i >= len(b):
            raise ValueError("truncated varint")
        x = b[i]
        i += 1
        val |= (x & 0x7F) << shift
        if not x & 0x80:
            return val, i
        shift += 7
        if shift > 70:
            raise ValueError("varint too long")


def parse_message(b: bytes) -> list[tuple[int, int, object]]:
    """Parse ``b`` as a protobuf message, consuming it fully or raising."""
    fields: list[tuple[int, int, object]] = []
    i, n = 0, len(b)
    while i < n:
        key, i = read_varint(b, i)
        field, wt = key >> 3, key & 7
        if field == 0:
            raise ValueError("field 0")
        if wt == 0:
            val, i = read_varint(b, i)
            fields.append((field, wt, val))
        elif wt == 1:
            if i + 8 > n:
                raise ValueError("truncated i64")
            fields.append((field, wt, b[i : i + 8]))
            i += 8
        elif wt == 5:
            if i + 4 > n:
                raise ValueError("truncated i32")
            fields.append((field, wt, b[i : i + 4]))
            i += 4
        elif wt == 2:
            ln, i = read_varint(b, i)
            if i + ln > n:
                raise ValueError("truncated len")
            fields.append((field, wt, b[i : i + ln]))
            i += ln
        else:
            raise ValueError(f"bad wire type {wt}")
    return fields


def classify_len(payload: bytes, depth: int) -> tuple[str, object]:
    if not payload:
        return "empty", None
    if depth < 12:
        try:
            sub = parse_message(payload)
            if sub and all(1 <= f[0] <= 536_870_911 for f in sub):
                return "message", sub
        except ValueError:
            pass
    try:
        payload.decode("utf-8")
        return "string", len(payload)
    except UnicodeDecodeError:
        return "bytes", len(payload)


class Node:
    __slots__ = ("wtypes", "max_repeat", "child", "scalars", "str_lens", "kinds")

    def __init__(self) -> None:
        self.wtypes: set[str] = set()
        self.max_repeat = 0
        self.child: dict[int, Node] | None = None
        self.scalars: set[int] = set()
        self.str_lens: set[int] = set()
        self.kinds: set[str] = set()


def merge(fields: list[tuple[int, int, object]], schema: dict[int, Node], depth: int) -> None:
    per_field = collections.Counter(f[0] for f in fields)
    seen: set[int] = set()
    for field, wt, payload in fields:
        node = schema.setdefault(field, Node())
        node.wtypes.add(WIRE[wt])
        if field not in seen:
            node.max_repeat = max(node.max_repeat, per_field[field])
            seen.add(field)
        if wt == 0 and isinstance(payload, int):
            if payload < 1_000_000_000_000 and len(node.scalars) < 6:
                node.scalars.add(payload)
        elif wt == 5 and isinstance(payload, (bytes, bytearray)):
            node.scalars.add(struct.unpack("<I", payload)[0])
        elif wt == 1 and isinstance(payload, (bytes, bytearray)):
            # fixed64. WIRE declares this type, so omitting it here silently
            # dropped every i64 sample from the reported scalars.
            node.scalars.add(struct.unpack("<Q", payload)[0])
        elif wt == 2 and isinstance(payload, (bytes, bytearray)):
            kind, info = classify_len(bytes(payload), depth)
            node.kinds.add(kind)
            if kind == "message":
                node.child = node.child or {}
                merge(info, node.child, depth + 1)  # type: ignore[arg-type]
            elif kind in ("string", "bytes") and isinstance(info, int):
                node.str_lens.add(info)


def render(schema: dict[int, Node], indent: int = 1) -> list[str]:
    out: list[str] = []
    pad = "  " * indent
    for field in sorted(schema):
        node = schema[field]
        wt = "/".join(sorted(node.wtypes))
        rep = " (repeated)" if node.max_repeat > 1 else ""
        line = f"{pad}#{field} [{wt}]{rep}"
        if node.kinds:
            line += " " + "/".join(sorted(node.kinds))
            lens = sorted(node.str_lens)
            if lens and node.kinds & {"string", "bytes"}:
                line += f" len={lens[0] if len(lens) == 1 else f'{lens[0]}..{lens[-1]}'}"
        if node.scalars and "message" not in node.kinds:
            line += f" = {sorted(node.scalars)[:6]}"
        out.append(line)
        if node.child:
            out.extend(render(node.child, indent + 1))
    return out


def main() -> None:
    if len(sys.argv) < 2:
        sys.exit(f"usage: {sys.argv[0]} <capture-dir> [method-substring]")
    directory = sys.argv[1]
    filt = sys.argv[2].lower() if len(sys.argv) > 2 else ""

    groups: dict[tuple[str, str], list[str]] = collections.defaultdict(list)
    for path in sorted(glob.glob(os.path.join(directory, "*.pb"))):
        method, direction, _idx = (
            os.path.basename(path).split("_", 1)[1].rsplit(".pb", 1)[0].split(".")
        )
        if filt and filt not in method.lower():
            continue
        groups[(method, direction)].append(path)

    for method, direction in sorted(groups):
        files = groups[(method, direction)]
        schema: dict[int, Node] = {}
        sizes, parsed = [], 0
        for path in files:
            with open(path, "rb") as fh:
                body = fh.read()
            sizes.append(len(body))
            try:
                merge(parse_message(body), schema, 0)
                parsed += 1
            except ValueError as exc:
                print(f"  !! {os.path.basename(path)}: {exc}")
        print(
            f"\n### {method}.{direction}  "
            f"(n={len(files)}, parsed={parsed}, bytes={min(sizes)}..{max(sizes)})"
        )
        print("\n".join(render(schema)))


if __name__ == "__main__":
    main()
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall