Skip to content

feat(library): write series, genres and tags into epub files - #58

Merged
audemed44 merged 1 commit into
mainfrom
feat/epub-library-metadata
Oct 24, 2026
Merged

audemed44 merged 1 commit into
mainfrom
feat/epub-library-metadata

Conversation

@audemed44

Copy link
Copy Markdown
Owner

Why

KOReader's Bookshelf plugin groups books by what KOReader extracts from the file itself (through CoverBrowser), so it never saw Shelfloom's series, series numbers, genres or tags.

What

Shelfloom now writes into each EPUB's OPF:

Shelfloom Written as KOReader / Bookshelf reads it as
Main series + number calibre:series, calibre:series_index Series and #N badge
Every series (EPUB 3 files) belongs-to-collection + collection-type / group-position Fallback series
Genres, then tags <dc:subject> each Keywords → Bookshelf's Genres
  • The main series is one the book has a number in, then the most specific (a sub-series before its parent).
  • Existing series/subject entries are replaced; nothing else in the OPF changes.
  • A sync runs ~5 s after any edit through the API (not KOReader progress sync) and at the end of every library scan. A per-book fingerprint (epub_metadata table) means a file is only rewritten when its metadata changes; books Shelfloom has nothing for are left alone.
  • Rewritten files get fresh hashes, with the old ones kept in book_hashes so KOReader still matches them.
  • Fixes rewriting EPUBs that store directory entries deflated (zip.Writer.Copy refuses them). Cover embedding was failing on these too.

Testing

  • Unit tests for the OPF editing (EPUB 2/3, prefixes, escaping, idempotence, clearing) and a server test for the sync (rename, untag, leave series, hashes, rescan skips).
  • Ran against a copy of the live library: all 705 EPUBs written (105 of them needed the directory fix), second pass writes nothing, every file passes a zip CRC check and well-formed XML check, calibre:series matches the DB for all of them, and a full rescan finds every file unchanged.

After deploy

The first sync rewrites about 650 EPUBs once. KOReader caches book info and doesn't notice that a file changed. To pick up the new metadata on the device, refresh the cached book information in the file browser (CoverBrowser).

KOReader only sees what's in the file, so plugins built on its book info
(Bookshelf) couldn't group books by Shelfloom's series or show its genres.
Each EPUB's OPF now gets:

- calibre:series and calibre:series_index for the main series (one the
  book has a number in, then the most specific), which KOReader reads
  first, plus EPUB 3 belongs-to-collection entries for every series;
- a <dc:subject> per genre and tag, which KOReader reads as keywords
  (Bookshelf's genres).

Existing series and subject entries are replaced; nothing else in the
file changes. A sync runs a few seconds after edits through the API and
at the end of every library scan. A fingerprint per book means a file is
only rewritten when its metadata changed, and a book Shelfloom knows
nothing about is left as it came. Rewritten files get their hashes
refreshed, keeping the old ones so KOReader still matches.

Also fixes rewriting EPUBs whose directory entries are stored deflated
(zip.Writer.Copy refuses them): cover embedding failed on those too.
@audemed44
audemed44 merged commit b89a334 into main Oct 24, 2026
2 checks passed
@audemed44
audemed44 deleted the feat/epub-library-metadata branch October 24, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant