Skip to content

Add add_sources.py: create a notebook & bulk-upload local sources#43

Open
Gavin-Thomas wants to merge 1 commit into
PleasePrompto:masterfrom
Gavin-Thomas:feat/add-sources-uploader
Open

Add add_sources.py: create a notebook & bulk-upload local sources#43
Gavin-Thomas wants to merge 1 commit into
PleasePrompto:masterfrom
Gavin-Thomas:feat/add-sources-uploader

Conversation

@Gavin-Thomas
Copy link
Copy Markdown

What this adds

scripts/add_sources.py — create a new NotebookLM notebook and bulk-upload local source files, end to end, from the CLI.

Why

Today the skill can authenticate and query notebooks, and notebook_manager.py add registers an existing notebook URL in the local library — but there's no way to create a notebook or upload sources. SKILL.md explicitly says "Manual upload required (user must add docs to NotebookLM)." This closes that loop, so the full workflow (create → upload → register → query) runs without leaving the CLI.

How it works

  • Reuses the existing authenticated persistent profile via BrowserFactory.launch_persistent_context, so it works immediately after auth_manager.py setup (same hybrid-auth / cookie-injection path as the rest of the skill).
  • Clicks Create new notebook, opens the upload dialog, and attaches all .txt/.md/.pdf files in --sources-dir in a single input[type=file] call (NotebookLM supports multi-file upload).
  • Waits for processing, then renames the notebook. NotebookLM's title is <input class="title-input">; it is set with Playwright fill() (clears + dispatches the input event Angular needs) followed by Tab to commit — avoiding the macOS Ctrl+A select-all pitfall.
  • Prints NOTEBOOK_URL: so the caller can immediately notebook_manager.py add it.

Robustness / safety

  • Multiple fallback locators for the create button and file input.
  • --probe opens the home page, screenshots, and dumps clickable labels to help adapt selectors if Google's UI shifts.
  • Flags: --headless, --keep-open, --rename-only <url>, --timeout-s.
  • Saves step-by-step screenshots to data/shots/ for verification/debugging.
  • No new dependencies (uses existing patchright + config/browser_utils), no changes to existing scripts, and nothing under data/ is touched or committed.

Usage

python scripts/run.py add_sources.py --sources-dir ./sources --name "My Docs"

Docs

README updated: Quick Start step 3 now shows an automated option, the commands table and architecture diagram list the script, and the "manual upload" limitation note is updated.

Testing

Verified end-to-end on macOS (real Chrome, Python 3.12): created a notebook, bulk-uploaded 13 .txt sources (confirmed the "(13)" source count in NotebookLM), renamed it, registered it via notebook_manager.py, and queried it successfully via ask_question.py.

🤖 Generated with Claude Code

…urces

The skill could authenticate and query notebooks, and notebook_manager.py
registers an existing notebook URL in the local library — but there was no way
to *create* a notebook or upload sources (SKILL.md notes "manual upload
required"). add_sources.py closes that loop.

- Reuses the authenticated persistent profile via BrowserFactory, so it works
  right after `auth_manager.py setup`.
- Creates a new notebook and bulk-uploads every .txt/.md/.pdf in a directory in
  a single input[type=file] call, then renames the notebook and prints the URL.
- Rename uses NotebookLM's <input class="title-input"> via fill()+Tab, avoiding
  the macOS Ctrl+A select-all pitfall.
- Defensive: fallback locators, --probe to inspect the UI, --headless,
  --keep-open, --rename-only, and step screenshots saved to data/shots/.
- No new dependencies; no changes to existing scripts; data/ untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant