Skip to content

Releases

ibook2epub 2.4.0

Choose a tag to compare

@raeq raeq released this 26 Sep 18:44
3c8c857

Highlights

  • Archives say which book they came from. Every archive written now carries a zip comment, ibook2epub/1 src=<digest>. The planner trusts it over a file's name or identifier, so a book that is renamed or moved keeps its archive. E-readers ignore the comment, and the book validates as before.
  • No more guessing. Suppose two books that nothing tells apart both want an archive that was written before markers existed. Neither is given it. Under --on-collision suffix each gets a name of its own; in skip mode each is reported as a collision.
  • --list shows copies too. PDFs and zipped epubs that are copied through are now listed (copy / copied).
  • A dry run refuses what the real run refuses. That covers the --min-free floor and a bad -ad, -ao, vault or --library-export destination. A dry run now exits 5 on these, where it used to go ahead.
  • Harder against hostile XML. A container, package document or encryption.xml that declares a DTD internal subset is refused, as is XML with more than 200,000 elements or nested deeper than 1,000 levels. This check refused none of the 2,804 books in a real library.
  • Many fixes to --on-collision suffix, Ctrl-C handling, notes and vaults, --verify and -ae -ar. See the changelog.

What you may notice

  • Archives written from now on are not byte-identical to what 2.3.1 wrote. The only difference is the zip comment.
  • --portable-names romanize needs disarm>=0.13,!=0.17.0. disarm 0.17.0 refused the separator this tool uses; 0.17.1 fixed it.
    • If you upgrade disarm to 0.17.1, titles containing a few rare characters get a new name. These are the schwa ə, Ǝ, 20 rare Latin letters, 12 Georgian Mtavruli capitals, and U+2028 / U+2029.
    • Such a book is exported again under its new name, and its old file is reported as an orphan. Nothing is deleted.

Full list of changes: CHANGELOG.md

ibook2epub 2.3.1

Choose a tag to compare

@raeq raeq released this 10 Sep 22:40
v2.3.1
67c3162

Fixes for an evicted library

If iCloud has moved your books off the Mac, this release stops ibook2epub from downloading them one at a time.

  • PDFs and already-zipped books are copied in parallel, by as many workers as -w sets. They were copied one at a time before conversion started, and on an evicted library every copy is a download. (#10)
  • --skip-incomplete covers them too. It checked Apple's book folders only, so an evicted PDF was downloaded anyway. A file whose copy is already on your shelf is not reported. (#12)
  • A zipped book is opened once per run under --name-by author-title, not twice, and not at all under --skip-incomplete when iCloud has evicted it. (#14)

Messages that say what happened

  • The summary says why books remain. A book that failed is reported as failed, and is no longer told to rerun or pass -m 0. (#15)
  • A missing Full Disk Access grant is told apart from a missing Books container. Each used to get the other's message. (#9)

One change a script can see

A refusal from macOS used to exit 4, "no library found". It now exits 8. If you script around the exit code and treat 4 as "fix the path", a refusal now comes back as 8, which means: grant the terminal Full Disk Access. (#19)

Full changes: CHANGELOG.md

ibook2epub 2.3.0

Choose a tag to compare

@raeq raeq released this 09 Sep 21:02
v2.3.0
e1f91d4

Take your library out of Apple Books

Apple gives no way to get a catalogue out. --library-export FILE reads the
BKLibrary database your highlights already come from and writes what you own:
title, author, when each book arrived, and the collections you sorted it onto.

A Goodreads-format CSV by default, which The StoryGraph and most other trackers
import directly. --library-format json writes the canonical record instead,
described by a shipped schema. It converts nothing, like -ao, and composes
with it.

ibook2epub --library-export ~/library.csv                       # for a tracker
ibook2epub --library-export ~/library.json --library-format json
ibook2epub --library-export --dry-run                           # just the estimate

It is a catalogue, not a reading history

Measured against a 3,620-book library, Apple holds titles, authors, collections
and acquisition dates for every book and little else: the rating is zero on
every row, and eleven books carry a finish date. So the exclusive shelf follows
the evidence and stays blank without it, rather than telling a tracker you
intend to read 3,389 books you merely bought. --unknown-shelf fills the blanks
with a value you choose.

Most rows will import unmatched, because most books carry a UUID rather than an
ISBN, and the run tells you before writing anything rather than after.

Also in this release

The package is four layers now — utils, collect, export, run — with a
test that fails if an import crosses upward.

Three defects in released code are fixed: a Markdown vault could write no notes
and report success, --annotations-only --dry-run wrote the file anyway, and a
Core Data date of 0 rendered as midnight on New Year's Day 2001.

One thing to know before upgrading: a run that converts nothing now refuses the
conversion flags it used to accept and ignore, so a command line carrying one
exits 2 instead of silently doing nothing with it.

Full notes in CHANGELOG.md.

ibook2epub 2.2.0

Choose a tag to compare

@raeq raeq released this 28 Aug 19:29

Your highlights, straight into an Obsidian vault.

--annotations-format markdown turns the detached export into one note per
book, with YAML frontmatter and the highlights as blockquotes. With it, -ad
and -ao name a directory rather than a file.

ibook2epub -ao ~/vault/Books --annotations-format markdown   # just the notes
ibook2epub -ad ~/vault/Books --annotations-format markdown   # convert too

-ae stays JSON: Markdown inside a zip serves nobody.

Your notes are yours

A vault note is a file you write in too, which is the whole point of putting
them there. So the file has four parts, and the tool owns exactly one:

the frontmatter yours, and Obsidian's — add tags and aliases freely
the marker line the tool's
the highlights between the markers the tool's
everything below the end marker yours

Only the middle is ever rewritten. Tag a note, add an alias, write three
paragraphs underneath — the next run still adds your new highlights and leaves
all of it alone. Edit inside the highlights and the tool stops touching that
note entirely, putting the new ones in a .md.new beside it, so you never have
to choose between keeping your edits and getting your highlights.

A rerun that finds nothing new writes nothing at all, so a vault in git stays
quiet.

One consequence worth knowing: the frontmatter is written once and never
rewritten, because it is yours from the moment it lands. Fix a wrong title
upstream and the note keeps the old one — delete the note and it comes back
correct.

Measured, not assumed

  • Frontmatter values from the book are quoted, always. 433 of 5,531 titles
    and authors in a real 2,805-book library break or change unquoted, 298 of them
    because they contain ": ", which starts a mapping and makes Obsidian show
    the note as having no properties at all — silently.
  • Names come from the library named once with .epub, suffix swapped on the
    result.
    Naming again with .md clamps long titles against a budget two
    bytes larger: across title lengths 180–339, 101 came out different, and a book
    near the limit would have been renamed the first time a second book crowded
    the name.
  • Notes are matched to books by filename, not dc:identifier. 21 canonical
    identifiers in that library are shared by 52 books — one ISBN covers three
    Martin novels, one template UUID covers three unrelated technical books.

Also fixed

  • The coverage gate reported failures and passed the build. coverage
    compares round(total, precision) against fail_under, and the precision
    defaulted to 0, so 96.92% rounded to 97 and exited 0 while the report printed
    FAIL. Anything from 96.5% up slipped through. It caught a real gap within the
    hour of being fixed.
  • The README's Command Line block had fallen two flags behind --help. It
    is derived from the parser now rather than pasted.

884 tests, 97.42% coverage. Full detail in the changelog.

ibook2epub 2.1.1

Choose a tag to compare

@raeq raeq released this 28 Aug 13:33

Two corrections to the annotations feature 2.1.0 shipped, both about whose work
an annotation is. Nothing about the export format changes, so a file written by
2.1.0 is still valid.

An annotation is the reader's own work

The module, the schema and the README all said an annotation's text "must not
be reproduced" for a DRM-protected book — and that claim was the stated
justification for keeping the cfi field.

It is wrong. An annotation is the reader's selection and their own note beside
it. It was never inside the protected file: Apple keeps it in a separate
database, and the licensing of a book says nothing about who owns the sentence
somebody chose to mark.

The behaviour was already right, so no export changes. A DRM-protected book is
skipped by the converter because its file cannot be opened, and its highlights
come out in full. The cfi field's real reason stands without the wrong one:
a text fragment cannot tell apart a phrase that appears more than once in one
book.

A guard now asserts that nothing in the annotations module reaches for
encryption state at all. Consulting it would be the first step towards
withholding a reader's own writing from them, and refusing the import is easier
than arguing with the idea later.

Highlights that reached no file are now reported

-ae puts a book's highlights inside the book, which needs the book to be on
the shelf. A book that was never converted has no archive to put them in, so
its highlights were read out of Apple's database and then reached nothing at
all — silently.

With a DRM-protected book that is permanent, since no rerun will ever open its
file. It is also exactly the book whose highlights are the only part you can
keep. The run now says so:

10 annotation(s) from 4 book(s) reached no file: Blindsight.epub, Dune.epub,
Neuromancer.epub, and 1 more. Those books are not on the shelf, so there was
nothing to embed them in — a DRM-protected book can never be converted, and its
highlights are the only part of it you can keep. Run again with
--annotations-detached FILE to write them to a file of their own, or
--annotations-only FILE to do that without converting anything.

So a locked library wants ibook2epub -ae -ad ~/highlights.json, or -ao on
its own. The warning stays quiet when -ad is already in force, because then
the highlights are in a file and there is nothing to report.

777 tests, 97.29% coverage. Full detail in the changelog.

ibook2epub 2.1.0

Choose a tag to compare

@raeq raeq released this 28 Aug 13:13

Apple keeps your highlights and notes in its own database, not in the books. So
converting a library got you the books and left the reading behind. This
release takes them with you.

ibook2epub -ao ~/highlights.json   # just the highlights, no conversion
ibook2epub -ae                     # convert, and put them inside each book
ibook2epub -ad ~/highlights.json   # convert, and write one file as well
ibook2epub -ae -ar                 # bring an older shelf up to date
ibook2epub -ao | jq '.annotations[].text'

Five flags cover three separate decisions: whether to gather them at all, where
they go, and whether to do that without converting anything.

Flag
-an, --annotations-none the default, stated so a script can be explicit
-ae, --annotations-embedded into each book, at META-INF/annotations.json
-ad, --annotations-detached [FILE] one file for the whole library
-ao, --annotations-only [FILE] that file and nothing else, no conversion
-ar, --annotations-refresh go back over books an earlier run converted

On macOS this needs Full Disk Access. Without it you get exit code 4 and a
message saying so, not a traceback.

Ahead of the spec, on purpose

The shape follows the direction of the W3C EPUB Annotations work rather
than its current draft, which still has T.B.D. sections and a normative
dependency on text fragments that has not landed in HTML. It does not claim
conformance.

The locator is a URL text fragment, which is what that work is converging on
and what any browser can act on. The EPUB CFI Apple records is kept in its own
field rather than thrown away: the group has explicitly ruled CFI out, but it
remains the only locator that still points at the right place when the
highlighted text appears more than once or must not be reproduced at all. The
schema is epubconvert/annotations.schema.json, shipped inside the package, so
the data can become conformant later without being gathered again.

Both places the spec defines are supported, because it prefers neither.
Detached annotations survive losing the books; an embedded set travels with the
book to whatever reads it next. -ae -ad FILE does both.

The identifier is a real key

Every annotation carries its book's own dc:identifier, resolved through the
package document's unique-identifier. Every other field naming a book is a
name that can change, so this is the only one that still matches an annotation
to its book after a rename, a re-download, or a move to somebody else's reader.

It is recorded canonically, because a key only works if the same book always
yields the same string, and books do not cooperate. A surveyed 2,805-book
library writes one ISBN six ways — bare, urn:isbn:, URN:ISBN:, hyphenated,
ISBN 978..., urn:ean: — and one UUID two ways. A verifiable ISBN becomes
urn:isbn: and thirteen digits, an ISBN-10 becomes the ISBN-13 naming the same
book, and a UUID becomes lowercase urn:uuid:. That rewrote 2,328 of 2,703.

Recognition is by check digit, never by counting digits: 68 identifiers in that
library are ten or thirteen digits and fail their check, so a length rule would
have relabelled every one as an ISBN it is not. Anything unrecognised passes
through untouched, and the declared form is kept as declaredIdentifier
whenever canonicalising changed it. Shelf naming still compares identifiers as
declared, because changing that would move filenames on shelves that exist.

Hardened before it shipped

A review of the feature found 43 issues. The critical one, all eleven highs and
every medium are fixed in this release. The four that mattered most all
destroyed annotations a reader may not be able to get back:

  • The detached export was written with a call that truncates before it writes,
    so an interrupted write left it as a prefix of itself — not valid JSON, and
    therefore refused by every later run.
  • A refresh deleted an annotation set it had not authored.
  • A file of the wrong shape was silently replaced rather than refused.
  • --dry-run was enforced at one of the two routes into the code that writes.

Nothing read from Apple is trusted now. Those columns are untyped and that
schema is undocumented, so one unusable row costs one annotation instead of the
whole export. The read-only database URI is built by Path.as_uri() rather than
by string concatenation, because a filename containing ? could append its own
parameters ahead of mode=ro and open the database writable.

Faster

A book is written once under -ae, with its annotations already inside, rather
than built and then rebuilt. Annotations are indexed once per run instead of
scanned once per book, which is 623x at 20,000 annotations. A refresh that
changes nothing no longer decompresses the whole archive to find that out:
peak allocation on a no-op drops from 7.86 MB to 0.09 MB on a 6.4 MB book.

766 tests, 97.37% coverage. Full detail in the changelog.

ibook2epub 2.0.4

Choose a tag to compare

@raeq raeq released this 27 Aug 20:47
pip install --upgrade ibook2epub

Fixed

  • Encryption is judged per block rather than per document. A book declaring one
    font-obfuscation block and one block naming no algorithm passed as
    unprotected, because the check counted blocks and collected algorithms as two
    flat totals and only fired when no block anywhere named one. Such a book
    exported as an archive that will not open and was recorded as finished work,
    which rerun safety then skips for ever — the exact failure the per-document
    check had been written to prevent.
  • A copy interrupted part-way through is counted. --no-copy-through's
    counterpart returned a total assigned only once the whole loop finished, so a
    Ctrl-C reported nothing copied while the files were already on disk.

Security

  • Cover extraction reads through open_contained like every other reader.
    shutil.copyfile opens its source with a plain open(), which follows a
    symlink, so resolving the path and then copying it reopened the
    check-then-open window O_NOFOLLOW exists to close. A test now fails the
    build if any module copies a file that way.
  • The entity-declaration guard asks the parser instead of reading the bytes.
    Two hand-written scans of the DOCTYPE declaration were defeated in turn —
    first by a SYSTEM identifier containing >, then by a comment holding a
    decoy <!DOCTYPE — because each had to re-derive where the declaration
    begins and ends. expat already knows, so it is asked.

Zero runtime dependencies. Python 3.10+.

ibook2epub 2.0.3

Choose a tag to compare

@raeq raeq released this 27 Aug 19:22
pip install --upgrade ibook2epub

Fixed

  • A package document is read once per run rather than twice. Planning and
    orphan detection each named every package, and naming reads a package
    document per book under --name-by author-title, so a real 2,805-book
    library was parsed 5,610 times for one listing. The two share an assignment
    when nothing narrowed the selection; under --match or -m they still name
    their own sets, because the shelf is judged against the whole library and the
    run against the subset.

Security

  • XML entity declarations in a package document or container are refused. An
    entity lets a small file expand into a large one, and the size cap cannot see
    it — the cap measures the file, the expansion happens after. expat has capped
    the amplification factor since 2.4, so a current Python already refuses the
    classic attack; the rule is stated here so it belongs to the tool rather than
    to whichever expat the interpreter was built against. Of 2,804 package
    documents in a real library, one carries a DOCTYPE and none declares an
    entity, so nothing real is refused.

Zero runtime dependencies. Python 3.10+.

ibook2epub 2.0.2

Choose a tag to compare

@raeq raeq released this 26 Aug 20:33
pip install --upgrade ibook2epub

Fixed

  • A dc:title of none was treated as a title. Some converters write that
    literal string into every metadata field a book has, including the one Apple
    derives its folder name from, and 31 books in a real library do. All 31 named
    themselves none.epub, collided with each other, and were suffixed into a
    pile — none.epub, none (2).epub, up to none (30).epub. A placeholder
    title is now no title, so those books keep the folder name Apple set, which
    is unique per book. Collisions across that library fall from 72 to 43.
    Matched whole and case-folded: None of This Is True is a real book. A
    creator of Unknown is deliberately left alone — 300 books declare it, and
    filing them together under U is a real answer where a title of none is not.

Zero runtime dependencies. Python 3.10+.

ibook2epub 2.0.1

Choose a tag to compare

@raeq raeq released this 26 Aug 14:53
pip install --upgrade ibook2epub

Fixes only. Three of them are places where a rule was applied on one path and
not on another, which is why they were invisible until someone ran a real
library through them.

Fixed

  • Copied files never met the naming layer. --portable-names sanitises the
    names of books it converts, and wrote a copied file's name verbatim — so a
    colon reached a shelf bound for a Kindle, which is the one thing the flag
    exists to prevent. --name-by author-title had the matching gap, leaving
    half a mixed library named the old way. An already-zipped epub is now named
    from its own dc:title and dc:creator like any other book; a PDF keeps its
    filename, cleaned.
  • --list printed the source package name rather than the name it would write,
    so previewing a renaming policy showed nothing about the renaming. The name
    was already computed correctly and the listing read the wrong field. This
    affected -p as far back as 1.2.0, where the difference was one character.
  • Clamping a name that carried an undecodable byte crashed the run.
    os.walk on a network share returns names with surrogate escapes; a
    surrogate is three UTF-8 bytes, so a byte limit landing inside one raised
    UnicodeDecodeError out of planning, outside any handler. Truncation now
    backs off to a character boundary. The measurement had been made safe for
    these names some time ago; the truncation had not.

Changed

  • The two package readers, one for an archive and one for an unpacked
    directory, now share everything except fetching the bytes. A book that is
    broken the same way is described the same way whichever shape it arrives in:
    the directory reader used to name container.xml where the archive reader
    named META-INF/container.xml.

Zero runtime dependencies. Python 3.10+.