multi-format-book-extractor
Skill109 starsChanged 37 days agoMITView on GitHub
Extract chapters from PDF, MOBI, and AZW3 book files into individual markdown files. Use when extracting non-EPUB books. PDF uses pymupdf with TOC-based chapter splitting and auto-OCR fallback (Gemini) for scanned/image-only PDFs; MOBI/AZW3 routes through calibre then epub-chapter-extractor.
- Reads credentials
- Installs packages
In this repository61 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- adviseSkill
- ai-crystallizeSkill
- analyze-kbSkill
- auto-discoverySkill
- benchmark-memorySkill
- brain-mergeSkill
- changelog-protocolSkill
- coherence-sweepSkill
- compute-lifecycleSkill
- create-articleSkill
- create-explanatory-imageSkill
- decideSkill
- deep-researchSkill
- detect-tensionsSkill
- dialecticSkill
- domain-watchSkill
- elicitation-techniquesSkill
- epistemic-classificationSkill
- epub-chapter-extractorSkill
- extract-document-insightsSkill
- extract-insightsSkill
- find-connectionsSkill
- first-runSkill
- get-perspective-onSkill
- get-youtube-transcriptSkill
- git-commit-pushSkill
- graduate-insightsSkill
- incubation-loopSkill
- ingest-sourceSkill
- insight-capture-formatSkill
- insight-interviewSkill
- integrate-recent-notesSkill
- learn-new-thingsSkill
- manage-reference-dataSkill
- manage-thinking-topicsSkill
- manage-watching-domainsSkill
- nano-banana-image-generatorSkill
- propagate-changeSkill
- quick-searchSkill
- reasoning-checksSkill
- recallSkill
- ref-auditSkill
- ref-bridgeSkill
- ref-ingestSkill
- ref-querySkill
- ref-reconcileSkill
- ref-refreshSkill
- refresh-indexSkill
- ref-supersedeSkill
- scheduled-runSkill
- scope-mountSkill
- search-vaultSkill
- self-diagnosticSkill
- start-hereSkill
- synthesize-insightsSkill
- talkSkill
- test-memory-systemSkill
- think-about-itSkill
- update-changelogSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 30
If output_dir is omitted, creates a folder named after the file in the same directory.
- Distinctive: line 46
Run OCR directly (e.g. to tune params or force it):
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Multi-Format Book Extractor
Extract chapters from PDF, MOBI, and AZW3 files into individual numbered markdown files. Mirrors the epub-chapter-extractor pattern for non-EPUB formats.
Dependencies
- PDF:
pymupdf— auto-installed via--with pymupdf - Scanned PDF OCR fallback:
requests(--with requests) + a Gemini key in$GEMINI_API_KEY/$GOOGLE_API_KEY(read fromcornelius/.envif unset) - MOBI / AZW3: calibre must be installed
brew install --cask calibre
Single Book
cd $PROJECT_ROOT/.claude/skills/multi-format-book-extractor && \
uv run --with pymupdf --with requests python extract_book.py "/path/to/book.pdf" [output_dir]If output_dir is omitted, creates a folder named after the file in the same directory.
Scanned / Image-Only PDFs (auto-OCR)
Some PDFs are pure page scans with no text layer — pymupdf extracts nothing
and would silently write empty files. extract_book.py now samples the text layer
first (_has_text_layer) and, when a PDF looks image-only, automatically routes it
to Gemini 2.5 Flash OCR (ocr_pdf.py).
- Renders each page to PNG (~180 DPI), batches pages per API call, transcribes
verbatim to Markdown (preserves verse line breaks, Sanskrit/Tibetan diacritics,
footnotes), and writes
NN_pages-S-E.mdchunk files. - Resumable: re-running skips chunk files already written (≥200 chars), so an interrupted long book picks up where it left off.
- Cost is ~$0.002/page on Flash (a 300-page book ≈ $0.60).
Run OCR directly (e.g. to tune params or force it):
cd $PROJECT_ROOT/.claude/skills/multi-format-book-extractor && \
uv run --with pymupdf --with requests python ocr_pdf.py "/path/to/scan.pdf" [output_dir] \
[--model gemini-2.5-flash] [--dpi 180] [--pages-per-call 5] [--pages-per-file 20] [--concurrency 6]Batch Extraction (Parallel)
Extract all PDFs, MOBIs, and AZW3s from a directory in parallel:
SKILL="$PROJECT_ROOT/.claude/skills/multi-format-book-extractor"
UVX="uv"
DIR="/path/to/books"
for book in "$DIR"/*.{pdf,mobi,azw3}; do
[ -f "$book" ] || continue
stem="${book%.*}"
[ -d "$stem" ] && echo "Skipping: $(basename "$book") (already extracted)" && continue
echo "Starting: $(basename "$book")"
(cd "$SKILL" && $UVX run --with pymupdf --with requests python extract_book.py "$book") &
done
wait
echo "All done"Output Format
Each book gets a subfolder named after the file (without extension):
book-name/
├── 01_introduction.md
├── 02_chapter-one.md
└── ...- PDF with TOC: one file per chapter (uses level-1 TOC; falls through to level-2 if < 5 top-level entries, e.g. books structured as Parts)
- PDF without TOC: 20-page chunks (
01_pages-1-20.md, etc.) - Scanned / image-only PDF: auto-routed to Gemini OCR → 20-page chunks (
01_pages-1-20.md) with<!-- page N -->markers - MOBI / AZW3: same output quality as epub-chapter-extractor (converts via calibre first)
After Extraction
open /path/to/books/Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

