
Ebook Extractor
- 100 installs
- 49 repo stars
- Updated February 11, 2026
- ratacat/claude-skills
Helps with ai & agent building tasks.
About
ebook-extractor is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted coding.
- ebook-extractor
- AI & Agent Building
- AI-coding skill
Ebook Extractor by the numbers
- 100 all-time installs (skills.sh)
- Ranked #4,267 of 16,556 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Jul 28, 2026 (Skillselion catalog sync)
npx skills add https://github.com/ratacat/claude-skills --skill ebook-extractorAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 100 |
|---|---|
| repo stars | ★ 49 |
| Last updated | February 11, 2026 |
| Repository | ratacat/claude-skills ↗ |
What it does
Helps with ai & agent building tasks.
Files
Ebook Text Extractor
Overview
Extract plain text from EPUB, MOBI, and PDF files using Python scripts. No LLM calls - pure text extraction.
Supported Formats
| Format | Tool Used | Notes |
|---|---|---|
| EPUB | ebooklib + BeautifulSoup | Direct parsing, preserves structure |
| MOBI | Calibre ebook-convert | Converts to EPUB first, then extracts |
PyMuPDF (fitz) | Fast, handles most PDFs well |
Usage
Unified extractor (auto-detects format):
python3 ~/.claude/skills/ebook-extractor/scripts/extract.py /path/to/book.epub
python3 ~/.claude/skills/ebook-extractor/scripts/extract.py /path/to/book.mobi
python3 ~/.claude/skills/ebook-extractor/scripts/extract.py /path/to/book.pdfOutput options:
# To stdout (default)
python3 scripts/extract.py book.epub
# To file
python3 scripts/extract.py book.epub -o output.txt
python3 scripts/extract.py book.epub > output.txtFormat-specific scripts:
python3 scripts/extract_epub.py book.epub
python3 scripts/extract_mobi.py book.mobi
python3 scripts/extract_pdf.py book.pdfSetup
# One-command setup (installs all dependencies)
~/.claude/skills/ebook-extractor/setup.sh
# Or manually:
pip install -r ~/.claude/skills/ebook-extractor/requirements.txt
brew install calibre # macOS, for MOBI supportScript Location
~/.claude/skills/ebook-extractor/scripts/
Common Issues
| Problem | Solution |
|---|---|
| Missing package | Run setup.sh or pip install -r requirements.txt |
| MOBI fails | Ensure Calibre is installed: brew install calibre |
| PDF garbled | Some PDFs are image-based; OCR needed (not supported) |
ebooklib
beautifulsoup4
PyMuPDF
#!/usr/bin/env python3
"""Extract text from EPUB files."""
import sys
from pathlib import Path
try:
import ebooklib
from ebooklib import epub
from bs4 import BeautifulSoup
except ImportError as e:
print(f"Missing dependency: {e}", file=sys.stderr)
print("Install with: pip install ebooklib beautifulsoup4", file=sys.stderr)
sys.exit(1)
def extract_text_from_epub(epub_path: str) -> str:
"""Extract all text content from an EPUB file."""
book = epub.read_epub(epub_path)
text_parts = []
for item in book.get_items():
if item.get_type() == ebooklib.ITEM_DOCUMENT:
content = item.get_content().decode('utf-8', errors='ignore')
soup = BeautifulSoup(content, 'html.parser')
# Remove script and style elements
for element in soup(['script', 'style', 'nav']):
element.decompose()
# Get text with reasonable whitespace handling
text = soup.get_text(separator='\n', strip=True)
if text.strip():
text_parts.append(text)
return '\n\n'.join(text_parts)
def main():
if len(sys.argv) < 2:
print("Usage: extract_epub.py <epub_file> [-o output_file]", file=sys.stderr)
sys.exit(1)
epub_path = sys.argv[1]
output_path = None
if '-o' in sys.argv:
idx = sys.argv.index('-o')
if idx + 1 < len(sys.argv):
output_path = sys.argv[idx + 1]
if not Path(epub_path).exists():
print(f"File not found: {epub_path}", file=sys.stderr)
sys.exit(1)
text = extract_text_from_epub(epub_path)
if output_path:
Path(output_path).write_text(text, encoding='utf-8')
print(f"Extracted to: {output_path}", file=sys.stderr)
else:
print(text)
if __name__ == '__main__':
main()
#!/usr/bin/env python3
"""Extract text from MOBI files using Calibre conversion."""
import subprocess
import sys
import tempfile
from pathlib import Path
# Import the EPUB extractor
script_dir = Path(__file__).parent
sys.path.insert(0, str(script_dir))
from extract_epub import extract_text_from_epub
def check_calibre():
"""Check if Calibre's ebook-convert is available."""
try:
subprocess.run(
['ebook-convert', '--version'],
capture_output=True,
check=True
)
return True
except (subprocess.CalledProcessError, FileNotFoundError):
return False
def extract_text_from_mobi(mobi_path: str) -> str:
"""Extract text from MOBI by converting to EPUB first."""
if not check_calibre():
print("Error: Calibre not found. Install with: brew install calibre", file=sys.stderr)
sys.exit(1)
# Convert MOBI to temporary EPUB
with tempfile.NamedTemporaryFile(suffix='.epub', delete=False) as tmp:
tmp_epub = tmp.name
try:
result = subprocess.run(
['ebook-convert', mobi_path, tmp_epub],
capture_output=True,
text=True
)
if result.returncode != 0:
print(f"Conversion failed: {result.stderr}", file=sys.stderr)
sys.exit(1)
# Extract text from the converted EPUB
return extract_text_from_epub(tmp_epub)
finally:
# Clean up temp file
Path(tmp_epub).unlink(missing_ok=True)
def main():
if len(sys.argv) < 2:
print("Usage: extract_mobi.py <mobi_file> [-o output_file]", file=sys.stderr)
sys.exit(1)
mobi_path = sys.argv[1]
output_path = None
if '-o' in sys.argv:
idx = sys.argv.index('-o')
if idx + 1 < len(sys.argv):
output_path = sys.argv[idx + 1]
if not Path(mobi_path).exists():
print(f"File not found: {mobi_path}", file=sys.stderr)
sys.exit(1)
text = extract_text_from_mobi(mobi_path)
if output_path:
Path(output_path).write_text(text, encoding='utf-8')
print(f"Extracted to: {output_path}", file=sys.stderr)
else:
print(text)
if __name__ == '__main__':
main()
#!/usr/bin/env python3
"""Extract text from PDF files using PyMuPDF."""
import sys
from pathlib import Path
try:
import fitz # PyMuPDF
except ImportError:
print("Missing dependency: PyMuPDF", file=sys.stderr)
print("Install with: pip install PyMuPDF", file=sys.stderr)
sys.exit(1)
def extract_text_from_pdf(pdf_path: str) -> str:
"""Extract all text content from a PDF file."""
doc = fitz.open(pdf_path)
text_parts = []
for page_num in range(len(doc)):
page = doc[page_num]
text = page.get_text()
if text.strip():
text_parts.append(text)
doc.close()
return '\n\n'.join(text_parts)
def main():
if len(sys.argv) < 2:
print("Usage: extract_pdf.py <pdf_file> [-o output_file]", file=sys.stderr)
sys.exit(1)
pdf_path = sys.argv[1]
output_path = None
if '-o' in sys.argv:
idx = sys.argv.index('-o')
if idx + 1 < len(sys.argv):
output_path = sys.argv[idx + 1]
if not Path(pdf_path).exists():
print(f"File not found: {pdf_path}", file=sys.stderr)
sys.exit(1)
text = extract_text_from_pdf(pdf_path)
if output_path:
Path(output_path).write_text(text, encoding='utf-8')
print(f"Extracted to: {output_path}", file=sys.stderr)
else:
print(text)
if __name__ == '__main__':
main()
#!/usr/bin/env python3
"""
Unified ebook text extractor.
Auto-detects format and extracts text from EPUB, MOBI, and PDF files.
"""
import sys
from pathlib import Path
# Add script directory to path for imports
script_dir = Path(__file__).parent
sys.path.insert(0, str(script_dir))
def detect_format(file_path: str) -> str:
"""Detect ebook format from file extension."""
ext = Path(file_path).suffix.lower()
format_map = {
'.epub': 'epub',
'.mobi': 'mobi',
'.azw': 'mobi',
'.azw3': 'mobi',
'.pdf': 'pdf',
}
return format_map.get(ext, 'unknown')
def extract_text(file_path: str) -> str:
"""Extract text from any supported ebook format."""
fmt = detect_format(file_path)
if fmt == 'epub':
from extract_epub import extract_text_from_epub
return extract_text_from_epub(file_path)
elif fmt == 'mobi':
from extract_mobi import extract_text_from_mobi
return extract_text_from_mobi(file_path)
elif fmt == 'pdf':
from extract_pdf import extract_text_from_pdf
return extract_text_from_pdf(file_path)
else:
print(f"Unsupported format: {Path(file_path).suffix}", file=sys.stderr)
print("Supported formats: .epub, .mobi, .azw, .azw3, .pdf", file=sys.stderr)
sys.exit(1)
def main():
if len(sys.argv) < 2:
print("Usage: extract.py <ebook_file> [-o output_file]", file=sys.stderr)
print("", file=sys.stderr)
print("Supported formats: EPUB, MOBI, AZW, AZW3, PDF", file=sys.stderr)
sys.exit(1)
file_path = sys.argv[1]
output_path = None
if '-o' in sys.argv:
idx = sys.argv.index('-o')
if idx + 1 < len(sys.argv):
output_path = sys.argv[idx + 1]
if not Path(file_path).exists():
print(f"File not found: {file_path}", file=sys.stderr)
sys.exit(1)
fmt = detect_format(file_path)
print(f"Detected format: {fmt.upper()}", file=sys.stderr)
text = extract_text(file_path)
if output_path:
Path(output_path).write_text(text, encoding='utf-8')
print(f"Extracted to: {output_path}", file=sys.stderr)
else:
print(text)
if __name__ == '__main__':
main()
#!/bin/bash
# Setup script for ebook-extractor skill
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "=== Ebook Extractor Setup ==="
echo
# Check Python
if ! command -v python3 &> /dev/null; then
echo "ERROR: Python 3 not found. Please install Python 3 first."
exit 1
fi
echo "✓ Python 3 found: $(python3 --version)"
# Install Python packages
echo
echo "Installing Python packages..."
pip3 install -q -r "$SCRIPT_DIR/requirements.txt"
echo "✓ Python packages installed"
# Check for Calibre (optional, for MOBI support)
echo
if command -v ebook-convert &> /dev/null; then
echo "✓ Calibre found (MOBI support enabled)"
else
echo "⚠ Calibre not found (MOBI support disabled)"
echo " To enable MOBI support, install Calibre:"
echo " macOS: brew install calibre"
echo " Linux: sudo apt install calibre"
fi
echo
echo "=== Setup complete ==="
echo
echo "Usage:"
echo " python3 $SCRIPT_DIR/scripts/extract.py <ebook_file>"
Related skills
AI & Agent Buildingagents