Skip to content

Commit 18665a4

Browse files
Saqooshaclaude
andcommitted
Prevent file overwrite on duplicate PDF downloads
- Add unique_path() helper to append number suffix when file exists - Apply to both cmd_process and cmd_download functions - Follow macOS Finder naming convention (e.g., slides 2.pdf) - Update documentation to reflect duplicate handling behavior Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1b31db8 commit 18665a4

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ AutoMeetsSlide/
6464
- Commands: `login`, `check-auth`, `process` (supports `--system-prompt` flag)
6565
- Communicates via JSON on stdout
6666
- Uses `notebooklm-py` library for NotebookLM API
67+
- Duplicate file handling: automatically appends a number suffix (e.g., `_slides 2.pdf`) when output file already exists
6768

6869
### Data Flow
6970
1. User drops file → FileItem added to queue (pending)

python-sidecar/notebooklm_sidecar.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919
from pathlib import Path
2020

2121

22+
def unique_path(path: Path) -> Path:
23+
"""Return a unique file path by appending a number if the file already exists.
24+
25+
Example: slides.pdf -> slides 2.pdf -> slides 3.pdf
26+
"""
27+
if not path.exists():
28+
return path
29+
stem = path.stem
30+
suffix = path.suffix
31+
parent = path.parent
32+
counter = 2
33+
while True:
34+
candidate = parent / f"{stem} {counter}{suffix}"
35+
if not candidate.exists():
36+
return candidate
37+
counter += 1
38+
39+
2240
def emit(status: str, message: str, **kwargs):
2341
"""Emit a JSON status message to stdout."""
2442
data = {"status": status, "message": message, **kwargs}
@@ -197,7 +215,7 @@ async def cmd_process(file_path: str, output_dir: str, system_prompt: str | None
197215
emit("progress", "Slide generation complete!")
198216

199217
# Download PDF
200-
output_file = output_dir / f"{file_path.stem}_slides.pdf"
218+
output_file = unique_path(output_dir / f"{file_path.stem}_slides.pdf")
201219
emit("progress", f"Downloading PDF to: {output_file}")
202220

203221
downloaded_path = await client.artifacts.download_slide_deck(
@@ -282,7 +300,7 @@ async def cmd_download(notebook_id: str, output_dir: str, name: str | None = Non
282300
try:
283301
async with await NotebookLMClient.from_storage() as client:
284302
file_name = f"{name}_slides.pdf" if name else "slides.pdf"
285-
output_file = output_dir / file_name
303+
output_file = unique_path(output_dir / file_name)
286304
downloaded_path = await client.artifacts.download_slide_deck(
287305
notebook_id,
288306
str(output_file),

0 commit comments

Comments
 (0)