Skip to main content

📚 CleanMyBooks

Clean and standardize messy book filenames using LLM + Google Books API.

CleanMyBooks takes chaotic ebook filenames like python.crash.course.2ndEd_FINAL_v2.pdf and renames them to a clean, consistent format:

Eric Matthes - Python Crash Course (2019).pdf

Features

  • 🧠 LLM-powered parsing via OpenRouter (GPT-4o-mini by default)
  • 🔍 Google Books verification for authoritative metadata
  • 📊 Confidence scoring — falls back to LLM if Google match is weak
  • ⚡ Parallel processing with configurable thread workers
  • 💾 JSON caching — avoids re-processing the same file twice
  • 🛡️ Safe renaming — dry-run mode, collision-safe, no overwrites
  • 📝 Supports: .pdf, .epub, .mobi, .azw, .azw3

Installation

From source

git clone https://github.com/yourusername/cleanmybooks.git
cd cleanmybooks
pip install -e .

From PyPI (once published)

pip install cleanmybooks

Setup

  1. Copy the example env file:
cp .env.example .env
  1. Add your OpenRouter API key to .env:
OPENROUTER_API_KEY=sk-or-v1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Get a free API key at openrouter.ai/keys.


Usage

Basic — rename all books in a folder

cleanmybooks /path/to/my/ebooks

Dry run — preview changes without renaming

cleanmybooks /path/to/my/ebooks --dry-run

Verbose output with more workers

cleanmybooks /path/to/my/ebooks --workers 8 --verbose

Adjust confidence threshold

cleanmybooks /path/to/my/ebooks --confidence-threshold 0.75

Lower threshold = trust LLM more. Higher threshold = require stronger Google Books match.

Clear the cache

cleanmybooks --clear-cache

CLI Options

Option Default Description
folder (required) Directory containing book files
--dry-run False Preview changes without renaming
--workers N 4 Number of parallel threads
--confidence-threshold FLOAT 0.6 Min similarity score to use Google result
--verbose False Enable debug logging
--cache-file PATH ~/.cleanmybooks_cache.json Custom cache file location
--clear-cache — Clear cache and exit

Example Input/Output

Original Filename Cleaned Filename
python.crash.course.2ndEd.pdf Eric Matthes - Python Crash Course (2019).pdf
DUNE_frank_herbert_scanned.epub Frank Herbert - Dune (1965).epub
clean_code_uncle_bob.pdf Robert C. Martin - Clean Code (2008).pdf
atomic_habits_james_clear_2018.epub James Clear - Atomic Habits (2018).epub
unknown_book_v3_FINAL.pdf Unknown Author - Unknown Title.pdf (graceful fallback)

Output Format

Author - Title (Year).ext

Multi-author books are collapsed to:

First Author et al. - Title (Year).ext

How It Works

filename.pdf
    │
    ▼
[LLM via OpenRouter]
    │  Parse: title, authors, year
    ▼
[Google Books API]
    │  Verify and enrich metadata
    ▼
[Confidence Score]
    │  Token-overlap similarity (Jaccard)
    │  ≥ threshold → use Google result
    │  < threshold → fall back to LLM result
    ▼
[Rename]
    │  Sanitize characters
    │  Resolve collisions
    │  Author - Title (Year).ext
    ▼
[Cache] → skip on next run

Environment Variables

Variable Description
OPENROUTER_API_KEY Required. Your OpenRouter API key

License

MIT

Metadata

Release files for cleanmybooks 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cleanmybooks 0.1.0
File Size Uploaded Provenance Actions
cleanmybooks-0.1.0.tar.gz 13.7 kB Without provenance Details for cleanmybooks-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cleanmybooks 0.1.0
File Interpreter ABI Platform Actions
cleanmybooks-0.1.0-py3-none-any.whl Python 3 none any Details for cleanmybooks-0.1.0-py3-none-any.whl

Total release size: 28.6 kB

Release files / cleanmybooks-0.1.0.tar.gz

Download URL cleanmybooks-0.1.0.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
444269c660d73818a83825adf5601c1efa6b0b357ded9a0de04943efda0ba4c2
BLAKE2b-256 checksum
How to use checksums
eadc4482aa73de6334a1a3fffed57ed541f90dcef8ffda585d9c8ad59a1a9038
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.6

Release files / cleanmybooks-0.1.0-py3-none-any.whl

Download URL cleanmybooks-0.1.0-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76c7544347c842db7ebd6a1fecb0a4cd392bf91a3994d6afbcff748672de15a4
BLAKE2b-256 checksum
How to use checksums
c2df1a4bd556421a08b5ff9018a85778254555cc447ed5033bf142248366f2f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.6

Security for cleanmybooks 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page