pingu-epubforge 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pingu_epubforge-0.1.0/.agents/skills/pingu-epubforge/SKILL.md +117 -0
- pingu_epubforge-0.1.0/LICENSE +21 -0
- pingu_epubforge-0.1.0/MANIFEST.in +18 -0
- pingu_epubforge-0.1.0/PKG-INFO +281 -0
- pingu_epubforge-0.1.0/README.md +243 -0
- pingu_epubforge-0.1.0/docs/DESIGN.md +206 -0
- pingu_epubforge-0.1.0/pyproject.toml +107 -0
- pingu_epubforge-0.1.0/setup.cfg +4 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/__init__.py +58 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/__version__.py +3 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/cli.py +1133 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/core/__init__.py +67 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/core/cover_utils.py +962 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/core/epub_io.py +221 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/core/layout_utils.py +384 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/core/models.py +417 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/core/xml_utils.py +301 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/mcp_server.py +399 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/py.typed +0 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/tools/__init__.py +20 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/tools/auditor.py +762 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/tools/cleaner.py +618 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/tools/compressor.py +579 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/tools/forge.py +219 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/tools/kindle_fixer.py +748 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/tools/metadata.py +346 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge/tools/pdf_converter.py +1184 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge.egg-info/PKG-INFO +281 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge.egg-info/SOURCES.txt +31 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge.egg-info/dependency_links.txt +1 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge.egg-info/entry_points.txt +4 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge.egg-info/requires.txt +13 -0
- pingu_epubforge-0.1.0/src/pingu_epubforge.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pingu-epubforge
|
|
3
|
+
description: >-
|
|
4
|
+
Use this skill when the user wants to inspect, validate, repair (Kindle E999,
|
|
5
|
+
broken TOC/footnotes, Unicode filenames), compress (PNG to JPEG, target size
|
|
6
|
+
under 45 MB), clean repeated margin/watermark images, or convert a digitally
|
|
7
|
+
typeset PDF into a reflowable EPUB using the pingu-epubforge CLI.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# pingu-epubforge Agent Skill
|
|
11
|
+
|
|
12
|
+
Use `pingu-epubforge` to inspect, clean, repair, compress, and build standards-compliant EPUB files safely without losing text or breaking table-of-contents anchors.
|
|
13
|
+
|
|
14
|
+
## Invocation
|
|
15
|
+
|
|
16
|
+
Prefer whichever command is available in the user's environment, and **always pass `--json`** so output is deterministic and easy to parse:
|
|
17
|
+
|
|
18
|
+
- Installed in current environment: `pingu-epubforge <command> ... --json` (or `epubforge`)
|
|
19
|
+
- Zero-install via `uv`: `uvx pingu-epubforge <command> ... --json`
|
|
20
|
+
- With PDF support (`pdf2epub`): `uvx --from "pingu-epubforge[pdf]" pingu-epubforge pdf2epub ... --json`
|
|
21
|
+
|
|
22
|
+
## Safety Rules
|
|
23
|
+
|
|
24
|
+
1. **Non-destructive by default:** Never pass `--in-place` unless the user explicitly asks to overwrite their original `.epub`. Default outputs (`*.fixed.epub`, `*.compressed.epub`, `*.cleaned.epub`, `*.forged.epub`) or `-o <path>` preserve the original file.
|
|
25
|
+
2. **Audit first:** Before modifying any EPUB, run `inspect` to identify the exact issues and archive size.
|
|
26
|
+
3. **Preview before deleting images:** Before running `clean` on repeated images, run `clean --dry-run --json` and summarize the candidate groups (hash, copies, dimensions, bytes saved) for the user, unless the user explicitly asked for an automatic one-step `forge --clean-repeated`.
|
|
27
|
+
4. **Always verify post-audit:** After every mutating command, confirm `audit_after.is_valid == true` in the JSON output before reporting success.
|
|
28
|
+
|
|
29
|
+
## Recommended Workflows
|
|
30
|
+
|
|
31
|
+
### 1. Diagnose an EPUB (`inspect`)
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pingu-epubforge inspect book.epub --json
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Key JSON fields to summarize for the user:
|
|
38
|
+
- `is_valid`, `error_count`, `warning_count`
|
|
39
|
+
- `issues[]` (`code`, `severity`, `location`, `message`) — e.g. `UNICODE_NFD_MISMATCH`, `NCX_MISSING_FILE`, `BROKEN_FOOTNOTE_BACKLINK`, `MISSING_XML_UTF8_DECL`, `OS_JUNK_FILE`
|
|
40
|
+
- `media` (`total_archive_bytes`, `png_count`, `jpeg_count`, `duplicate_groups[]`)
|
|
41
|
+
|
|
42
|
+
Note: `inspect` exits with code `1` when `is_valid` is `false` (this is expected; still parse stdout JSON).
|
|
43
|
+
|
|
44
|
+
### 2. Repair Kindle / E-Reader Compatibility (`fix`)
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pingu-epubforge fix book.epub --clean-toc --json
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Use when `inspect` reports Unicode NFD/non-ASCII filenames, broken `toc.ncx` / `nav.xhtml` targets, misaligned footnote back-links, missing UTF-8 XML declarations, EPUB 2/3 OPF schema mismatches (`EPUB2_INVALID_PROPERTIES`, `EPUB3_MISSING_MODIFIED`, `EPUB3_MISSING_SVG_PROPERTY`), OS junk, or dot-leader page numbers in the TOC. Add `--normalize-layout` when Word/Calibre exports cause huge whole-paragraph dialogue indents (`display: table` + left padding) or double line spacing.
|
|
51
|
+
|
|
52
|
+
### 3. Reduce File Size (`compress`)
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pingu-epubforge compress book.epub --max-mb 45 --max-height 2048 --json
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- Converts opaque PNGs (including opaque RGBA) to collision-safe JPEGs while preserving genuinely transparent PNGs by default.
|
|
59
|
+
- Add `--flatten-alpha` only if the user agrees to flatten transparent PNGs onto white for extra size savings.
|
|
60
|
+
- Check `target_met`, `saved_percent`, `quality_used`, and `audit_after.is_valid`.
|
|
61
|
+
|
|
62
|
+
### 4. Remove Repeated Margin / Watermark Images (`clean`)
|
|
63
|
+
|
|
64
|
+
Step 1 — Preview first:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pingu-epubforge clean book.epub --dry-run --min-repeats 5 --json
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Step 2 — Apply (optionally targeting specific hashes from `candidates[].sha256` with `--hash <prefix>`):
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pingu-epubforge clean book.epub --min-repeats 5 --clean-toc --json
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- Preserves chapter/page anchor `id` attributes (e.g. `<p id="page_12">`) by migrating them to the next sibling element or keeping a lightweight anchor so `toc.ncx` links remain valid.
|
|
77
|
+
- The `--max-area-ratio 0.5` safeguard protects full-page illustrations from accidental removal.
|
|
78
|
+
|
|
79
|
+
### 5. All-in-One Preparation (`forge`)
|
|
80
|
+
|
|
81
|
+
When the user wants a book fully prepared for Send to Kindle or Kobo in one step:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pingu-epubforge forge book.epub --max-mb 45 --clean-repeated --fix-kindle --clean-toc --json
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Runs `clean` → `fix` → `compress` in an isolated temporary workspace, writes `<name>.forged.epub` atomically, and audits the final archive.
|
|
88
|
+
|
|
89
|
+
### 6. Inspect or Edit Metadata (`metadata`)
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
# Read current metadata without modifying the EPUB
|
|
93
|
+
pingu-epubforge metadata book.epub --json
|
|
94
|
+
|
|
95
|
+
# Update selected fields (unspecified fields remain untouched)
|
|
96
|
+
pingu-epubforge metadata book.epub --title "Book Title" --author "Author Name" --series "My Series" --series-index 1 --lang en --json
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 7. Convert a Typeset PDF to Reflowable EPUB (`pdf2epub`)
|
|
100
|
+
|
|
101
|
+
Requires the optional `[pdf]` extra (`pymupdf`):
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
pingu-epubforge pdf2epub manuscript.pdf -o book.epub --title "Book Title" --author "Author Name" --lang en --json
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
- Adjust `--margin-top` / `--margin-bottom` (defaults `0.07`) if running headers or page numbers remain.
|
|
108
|
+
- Adjust `--min-image-area` (default `0.15`) or `--repeat-threshold` (default `3`) if illustrations are over- or under-filtered.
|
|
109
|
+
- Cover resolution priority: `--cover-image <file>` (JPG/PNG/WebP/TIFF/BMP → JPEG) → `--cover-page N` (optional `--cover-image-index K` when a page holds multiple visible images; errors if none) → automatic sidecar image with the same filename next to the PDF (e.g. `book.pdf` + `book.tiff`) → auto-detect within the first 5 pages (`--cover-search-pages`, automatically ignoring off-page pasteboard images and preferring portrait artwork). Normalized to `1600x2560` (`1:1.6`) by default; override with `--cover-size WxH` / `apple` / `keep` or `--no-cover`. Dedicated illustration pages are centered in full-page SVG wrappers (`--fit-illustrations`, opt out with `--no-fit-illustrations`) while horizontal artwork is never cropped.
|
|
110
|
+
|
|
111
|
+
## Reporting Results to the User
|
|
112
|
+
|
|
113
|
+
Always present a concise summary containing:
|
|
114
|
+
- Output file path
|
|
115
|
+
- Before/after file size and percentage saved (when applicable)
|
|
116
|
+
- Key repairs/removals performed (actions, migrated anchors, converted images)
|
|
117
|
+
- Post-audit status (`audit_after.is_valid`, remaining errors/warnings)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Angel Daniel Sanchez Castillo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
include pyproject.toml
|
|
4
|
+
include docs/DESIGN.md
|
|
5
|
+
include .agents/skills/pingu-epubforge/SKILL.md
|
|
6
|
+
|
|
7
|
+
recursive-include src/pingu_epubforge *.py py.typed
|
|
8
|
+
|
|
9
|
+
prune local_samples
|
|
10
|
+
prune sandbox
|
|
11
|
+
prune private_tests
|
|
12
|
+
prune out
|
|
13
|
+
prune tests
|
|
14
|
+
prune .github
|
|
15
|
+
|
|
16
|
+
global-exclude *.epub *.pdf *.mobi *.azw3 *.kfx *.cbz *.cbr *.fb2
|
|
17
|
+
global-exclude .DS_Store __MACOSX Thumbs.db ._*
|
|
18
|
+
global-exclude *.py[cod] __pycache__ uv.lock
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pingu-epubforge
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Modular Python library and CLI for creating, cleaning, compressing, validating, and repairing EPUB files.
|
|
5
|
+
Author-email: Angel Daniel Sanchez Castillo <angeldaniel.sanchezcastillo@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/AngelDanielSanchezCastillo/pingu-epubforge
|
|
8
|
+
Project-URL: Repository, https://github.com/AngelDanielSanchezCastillo/pingu-epubforge
|
|
9
|
+
Project-URL: Issues, https://github.com/AngelDanielSanchezCastillo/pingu-epubforge/issues
|
|
10
|
+
Keywords: epub,ebook,kindle,kobo,publishing,cli,validator,compressor
|
|
11
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Text Processing :: Markup :: XML
|
|
22
|
+
Classifier: Topic :: Utilities
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.11
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: typer>=0.12.0
|
|
28
|
+
Requires-Dist: pillow>=10.0.0
|
|
29
|
+
Requires-Dist: lxml>=5.0.0
|
|
30
|
+
Provides-Extra: pdf
|
|
31
|
+
Requires-Dist: pymupdf>=1.24.0; extra == "pdf"
|
|
32
|
+
Provides-Extra: mcp
|
|
33
|
+
Requires-Dist: mcp>=2.0.0; extra == "mcp"
|
|
34
|
+
Provides-Extra: all
|
|
35
|
+
Requires-Dist: pymupdf>=1.24.0; extra == "all"
|
|
36
|
+
Requires-Dist: mcp>=2.0.0; extra == "all"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# pingu-epubforge
|
|
40
|
+
|
|
41
|
+
**Modular Python library and CLI for inspecting, repairing, compressing, cleaning, and building standards-compliant EPUB files.**
|
|
42
|
+
|
|
43
|
+
Designed for independent authors, small creators, and e-reader users who want reliable books on Kindle (Send to Kindle), Kobo, and Apple Books without silent content loss.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- **`inspect` / `audit`** — Deep structural and Kindle-compatibility validator:
|
|
50
|
+
- Enforces EPUB ZIP packaging (`mimetype` first, uncompressed `ZIP_STORED`, exact bytes `application/epub+zip`, no `.DS_Store` / `__MACOSX/`).
|
|
51
|
+
- Detects Unicode NFC vs. NFD filename mismatches (a common Send to Kindle `E999` root cause) and non-ASCII filenames.
|
|
52
|
+
- Verifies manifest, spine, `toc.ncx`, EPUB 3 `nav.xhtml`, internal `<img>` / `<a>` targets, footnote back-links, XML well-formedness, and UTF-8 XML declarations.
|
|
53
|
+
- Summarizes archive size, PNG/JPEG counts, real alpha transparency, and SHA-256 duplicate image groups.
|
|
54
|
+
- **`fix`** — Safe, deterministic structural repair:
|
|
55
|
+
- Normalizes non-ASCII / NFD filenames to collision-safe ASCII and updates all OPF, NCX, NAV, XHTML, and CSS `url(...)` references.
|
|
56
|
+
- Automatically repairs broken `toc.ncx` / `nav.xhtml` targets and misaligned footnote back-links when the anchor ID exists uniquely in another chapter.
|
|
57
|
+
- Adds explicit `<?xml version="1.0" encoding="utf-8"?>` declarations, repairs malformed HTML4 tags, normalizes book covers to the standard `1600x2560` (`1:1.6`) Kindle/Apple Books proportion (configurable via `--cover-size WxH` or `--cover-size keep`), and optionally strips printed-PDF dot leaders (`--clean-toc`).
|
|
58
|
+
- Re-packages non-destructively (`book.fixed.epub` by default) and audits the output automatically.
|
|
59
|
+
- **`compress`** — Smart image optimizer with target-size mode:
|
|
60
|
+
- Inspects PNG alpha channels with Pillow: converts opaque PNGs (RGB or opaque RGBA) to collision-safe JPEGs while preserving genuinely transparent PNGs by default.
|
|
61
|
+
- Supports proportional downscaling (`--max-width`, `--max-height`) and adaptive `--max-mb` target-size mode without multi-generation JPEG loss.
|
|
62
|
+
- **`clean`** — Repeated margin/watermark image cleaner:
|
|
63
|
+
- Detects duplicate image payloads by SHA-256 (both repeated copies and single heavily referenced assets), with `--dry-run` preview and `--max-area-ratio` safeguard to protect full-page illustrations.
|
|
64
|
+
- **Anchor-preserving DOM cleanup:** when removing empty wrappers like `<p id="page_12"><img .../></p>`, migrates the `id` attribute to the next sibling (or keeps a lightweight anchor) so `toc.ncx` chapter jumps never break.
|
|
65
|
+
- **`metadata`** — View or edit Dublin Core and series metadata (`--title`, `--author`, `--lang`, `--publisher`, `--date`, `--description`, `--subject`, `--series`, `--series-index`, `--identifier`) non-destructively while keeping unspecified fields intact and syncing `toc.ncx` `<docTitle>`.
|
|
66
|
+
- **`forge`** — One-command pipeline (`clean` → `fix` → `compress` + optional metadata overrides) with atomic output and automatic post-audit.
|
|
67
|
+
- **`pdf2epub`** *(optional `[pdf]` extra)* — Geometric PDF → reflowable EPUB converter:
|
|
68
|
+
- Flexible cover resolution: supports `--cover-image <file>` (JPG, PNG, WebP, TIFF, BMP, GIF → JPEG), automatic sidecar detection next to the PDF (`manuscript.pdf` + `manuscript.tiff`), explicit `--cover-page N` (validating an image exists on that page), or automatic detection across the first 5 front-matter pages (`--cover-search-pages`), normalized to `1600x2560` (`1:1.6`) or custom `--cover-size` / `keep` / `--no-cover`.
|
|
69
|
+
- Renders dedicated illustration pages in centered full-page SVG wrappers so facing pages align cleanly in Apple Books & Kindle: gently fits near-standard portrait art (`--fit-illustrations`, opt out via `--no-fit-illustrations`) and keeps horizontal/landscape art uncropped and centered.
|
|
70
|
+
- Crops running header/footer margin zones, filters repeated logos and tiny icons, reconstructs wrapped paragraphs, detects chapters, and generates valid EPUB 2 + EPUB 3 navigation.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Installation
|
|
75
|
+
|
|
76
|
+
Requires **Python 3.11+**.
|
|
77
|
+
|
|
78
|
+
### With `uv` (recommended)
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Run directly without installing globally
|
|
82
|
+
uvx pingu-epubforge --help
|
|
83
|
+
|
|
84
|
+
# Add to a project (core EPUB tools)
|
|
85
|
+
uv add pingu-epubforge
|
|
86
|
+
|
|
87
|
+
# With optional geometric PDF-to-EPUB support (PyMuPDF)
|
|
88
|
+
uv add "pingu-epubforge[pdf]"
|
|
89
|
+
|
|
90
|
+
# With optional MCP 2.0 server support (for Claude Desktop, Antigravity, Cursor, etc.)
|
|
91
|
+
uv add "pingu-epubforge[mcp]"
|
|
92
|
+
|
|
93
|
+
# Everything (PDF + MCP)
|
|
94
|
+
uv add "pingu-epubforge[all]"
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### With `pip`
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
pip install pingu-epubforge
|
|
101
|
+
# Optional extras:
|
|
102
|
+
pip install "pingu-epubforge[pdf]"
|
|
103
|
+
pip install "pingu-epubforge[mcp]"
|
|
104
|
+
pip install "pingu-epubforge[all]"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Both `pingu-epubforge` and the short alias `epubforge` are installed as CLI commands (plus `pingu-epubforge-mcp` for the optional MCP server).
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## CLI Quickstart
|
|
112
|
+
|
|
113
|
+
All mutating commands are **non-destructive by default** (writing `<name>.fixed.epub`, `<name>.compressed.epub`, `<name>.cleaned.epub`, or `<name>.forged.epub`). Pass `-o output.epub` for a custom destination or `--in-place` to overwrite atomically. Every command also supports `--json` for scripting and CI pipelines.
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# 1. Inspect an EPUB for structural & Send to Kindle issues
|
|
117
|
+
pingu-epubforge inspect book.epub
|
|
118
|
+
pingu-epubforge inspect book.epub --json
|
|
119
|
+
|
|
120
|
+
# 2. Repair Kindle E999 filename/navigation/encoding issues, TOC dot leaders, and Word/Calibre indents
|
|
121
|
+
pingu-epubforge fix book.epub --clean-toc --normalize-layout
|
|
122
|
+
|
|
123
|
+
# 3. Compress opaque PNGs to JPEG and fit under 45 MB (Send to Kindle limit)
|
|
124
|
+
pingu-epubforge compress book.epub --max-mb 45 --max-height 2048
|
|
125
|
+
|
|
126
|
+
# 4. Preview and remove repeated margin/watermark images safely
|
|
127
|
+
pingu-epubforge clean book.epub --dry-run
|
|
128
|
+
pingu-epubforge clean book.epub --min-repeats 5
|
|
129
|
+
|
|
130
|
+
# 5. All-in-one pipeline: clean + fix + compress
|
|
131
|
+
pingu-epubforge forge book.epub --max-mb 45 --clean-repeated --fix-kindle --clean-toc
|
|
132
|
+
|
|
133
|
+
# 6. View or edit EPUB metadata (unspecified fields stay untouched)
|
|
134
|
+
pingu-epubforge metadata book.epub
|
|
135
|
+
pingu-epubforge metadata book.epub --title "Book Title" --author "Author Name" --series "My Series" --series-index 1
|
|
136
|
+
|
|
137
|
+
# 7. Convert a digitally typeset PDF into a reflowable EPUB (requires [pdf] extra)
|
|
138
|
+
pingu-epubforge pdf2epub manuscript.pdf -o book.epub --title "Chapter Collection" --author "Author Name" --lang en
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Python Library Usage
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from pingu_epubforge import audit_epub, clean_epub, compress_epub, fix_epub, forge_epub
|
|
147
|
+
|
|
148
|
+
report = audit_epub("book.epub")
|
|
149
|
+
print(report.is_valid, len(report.errors), len(report.warnings))
|
|
150
|
+
|
|
151
|
+
fixed = fix_epub("book.epub", clean_toc=True)
|
|
152
|
+
print("Fixed output:", fixed.output_path, "valid:", fixed.audit_after.is_valid)
|
|
153
|
+
|
|
154
|
+
cleaned = clean_epub("book.epub", dry_run=True, min_repeats=5)
|
|
155
|
+
print("Repeated image groups found:", len(cleaned.candidates))
|
|
156
|
+
|
|
157
|
+
forged = forge_epub(
|
|
158
|
+
"book.epub",
|
|
159
|
+
clean_repeated=True,
|
|
160
|
+
fix_kindle=True,
|
|
161
|
+
max_mb=45.0,
|
|
162
|
+
)
|
|
163
|
+
print(f"Saved {forged.saved_percent:.1f}% -> {forged.output_path}")
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Use with an AI Assistant (No Coding Required)
|
|
169
|
+
|
|
170
|
+
You do **not** need to memorize terminal commands to use `pingu-epubforge`. Once connected to an AI assistant via **MCP** (Model Context Protocol), you can simply ask in plain language to inspect, fix, compress, clean, edit metadata, or convert a PDF to EPUB. Everything runs **100% locally on your computer** (your books are never uploaded anywhere, and the server starts and stops automatically with your AI app).
|
|
171
|
+
|
|
172
|
+
### Step 1 — Install `uv` (one-time setup)
|
|
173
|
+
|
|
174
|
+
`uv` downloads Python and `pingu-epubforge` automatically on demand so you never have to manage virtual environments:
|
|
175
|
+
|
|
176
|
+
- **macOS / Linux** (paste into Terminal):
|
|
177
|
+
```bash
|
|
178
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
179
|
+
```
|
|
180
|
+
- **Windows** (paste into PowerShell):
|
|
181
|
+
```powershell
|
|
182
|
+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Restart your terminal / AI app after installing `uv`.
|
|
186
|
+
|
|
187
|
+
### Step 2 — Connect `pingu-epubforge` to your AI app
|
|
188
|
+
|
|
189
|
+
Choose the app you use (replace `pingu-epubforge[all]` with `pingu-epubforge[mcp]` if you do not need PDF conversion):
|
|
190
|
+
|
|
191
|
+
#### OpenCode
|
|
192
|
+
Add the `mcp` block to `~/.config/opencode/opencode.json` (or `opencode.json` in a folder), restart OpenCode, and run `/mcps` to confirm it is connected:
|
|
193
|
+
|
|
194
|
+
```json
|
|
195
|
+
{
|
|
196
|
+
"$schema": "https://opencode.ai/config.json",
|
|
197
|
+
"mcp": {
|
|
198
|
+
"pingu-epubforge": {
|
|
199
|
+
"enabled": true,
|
|
200
|
+
"type": "local",
|
|
201
|
+
"command": ["uvx", "--from", "pingu-epubforge[all]", "pingu-epubforge-mcp"]
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### Visual Studio Code (Copilot Chat)
|
|
208
|
+
**Easiest way (no JSON editing):**
|
|
209
|
+
1. Press `Cmd+Shift+P` (macOS) or `Ctrl+Shift+P` (Windows/Linux).
|
|
210
|
+
2. Type and select **`MCP: Add Server`**.
|
|
211
|
+
3. Choose **`Command (stdio)`**.
|
|
212
|
+
4. Enter: `uvx --from pingu-epubforge[all] pingu-epubforge-mcp`
|
|
213
|
+
5. Name it `pingu-epubforge` and choose **Global** (available everywhere) or **Workspace**.
|
|
214
|
+
|
|
215
|
+
Or save `.vscode/mcp.json` manually:
|
|
216
|
+
|
|
217
|
+
```json
|
|
218
|
+
{
|
|
219
|
+
"servers": {
|
|
220
|
+
"pingu-epubforge": {
|
|
221
|
+
"command": "uvx",
|
|
222
|
+
"args": ["--from", "pingu-epubforge[all]", "pingu-epubforge-mcp"]
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Claude Desktop, Gemini CLI, Cursor, or Antigravity
|
|
229
|
+
Add this block to your client's MCP config file (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS, `%APPDATA%\Claude\claude_desktop_config.json` on Windows, `~/.gemini/settings.json` for Gemini CLI, or `.cursor/mcp.json` for Cursor) and restart the app:
|
|
230
|
+
|
|
231
|
+
```json
|
|
232
|
+
{
|
|
233
|
+
"mcpServers": {
|
|
234
|
+
"pingu-epubforge": {
|
|
235
|
+
"command": "uvx",
|
|
236
|
+
"args": ["--from", "pingu-epubforge[all]", "pingu-epubforge-mcp"]
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Step 3 — Ask your AI assistant in plain language
|
|
243
|
+
|
|
244
|
+
Once connected, open a chat in your AI app and ask things like:
|
|
245
|
+
|
|
246
|
+
- *"Inspect `/path/to/book.epub` and tell me if it has any Kindle compatibility problems."*
|
|
247
|
+
- *"Prepare `/path/to/book.epub` for Send to Kindle: compress it under 45 MB, clean the table of contents, and fix excessive dialogue indentation."*
|
|
248
|
+
- *"Check `/path/to/book.epub` for repeated watermark images (preview first before removing)."*
|
|
249
|
+
- *"Convert `/path/to/manuscript.pdf` into an EPUB in Spanish using `/path/to/cover.png` as the cover."*
|
|
250
|
+
- *"Update the title, author, and series metadata of `/path/to/book.epub`."*
|
|
251
|
+
|
|
252
|
+
All operations are **non-destructive by default** (your original file stays untouched unless you explicitly ask to overwrite it).
|
|
253
|
+
|
|
254
|
+
Exposed MCP tools: `inspect_epub`, `fix_epub`, `compress_epub`, `clean_epub` (defaults to `dry_run=True`), `forge_epub`, `convert_pdf_to_epub`, `get_epub_metadata`, and `update_epub_metadata`.
|
|
255
|
+
|
|
256
|
+
### Alternative: Agent Skill (`SKILL.md`) — Zero Extra Dependencies
|
|
257
|
+
|
|
258
|
+
For terminal-capable agents (**Antigravity**, **Claude Code**, **Codex**, **Cursor**, **Gemini CLI**, **OpenCode**), this repository also includes a ready-to-use Agent Skill at [`.agents/skills/pingu-epubforge/SKILL.md`](.agents/skills/pingu-epubforge/SKILL.md). It guides the agent through the safe CLI workflow (`inspect --json` → `clean --dry-run --json` → `forge --json` → verify `audit_after.is_valid`) using `uvx pingu-epubforge`.
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Development
|
|
263
|
+
|
|
264
|
+
This repository uses [`uv`](https://docs.astral.sh/uv/) and `pre-commit`:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
uv sync --all-groups --all-extras
|
|
268
|
+
uv run pre-commit install
|
|
269
|
+
uv run pre-commit run --all-files
|
|
270
|
+
uv run pytest --cov=pingu_epubforge --cov-report=term-missing
|
|
271
|
+
uv run mypy src
|
|
272
|
+
uv build
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
All automated tests generate 100% synthetic EPUB and PDF fixtures programmatically at runtime. Never commit real books, manuscripts, or copyrighted files.
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## License
|
|
280
|
+
|
|
281
|
+
MIT License — Copyright (c) 2026 Angel Daniel Sanchez Castillo. See [LICENSE](LICENSE).
|