Skip to content

Update kobo.py to include subtitle if field exists in custom columns#3358

Open
dotknott wants to merge 1 commit into
janeczku:masterfrom
dotknott:master
Open

Update kobo.py to include subtitle if field exists in custom columns#3358
dotknott wants to merge 1 commit into
janeczku:masterfrom
dotknott:master

Conversation

@dotknott
Copy link
Copy Markdown

@dotknott dotknott commented Apr 8, 2025

Since Subtitle is becoming more common in Calibre DB setups with Kobo users, I added subtitle to the sync data when there's a custom column labeled 'subtitle'. When no matching column exists it returns an empty string.

@szkafen
Copy link
Copy Markdown

szkafen commented Apr 9, 2025

In my particular case, I wanted the subtitle field to show the number of pages as, e.g., "256 pages". This solution seems to only like columns with plain text or numbers. I made the #subtitle column be populated with integers from Count Words and it worked, however it only outputed "256", which was only half my desired end goal.

I tried making a new #subtitle column, having it referencing the number column and with the template {#pages:} pages. The output of the column was indeed "256 pages", but sync would fail allways. It seems it doesn't like templates.

However, I found a solution. Going back to making the #subtitle column be the one populated by Count Pages and changing line 440 to return str(subtitleColumn[0].value) + " pages" worked flawlessly, and outputed the desired outcome in the Kobo. Here, " pages" can be changed to the desired word (in my case, since I want to respect Spanish grammar, " páginas"). It could also be changed to return "Pgs: " + str(subtitleColumn[0].value) or whatever to show variants of this output.

@AsherMaximum
Copy link
Copy Markdown
Contributor

I've made #3376 to make the subtitle sent to Kobo devices a config option in the Admin Feature settings, along with an option to add a suffix and/or prefix to it, which should cover both @dotknott's and @szkafen's use cases.

new-usemame added a commit to new-usemame/Calibre-Web-NextGen that referenced this pull request May 20, 2026
…ata (#267)

Backport of janeczku/calibre-web PR #3358 (@dotknott). Calibre libraries commonly store per-book subtitles in a custom column (especially non-fiction, academic). The Kobo sync protocol has a Subtitle key in the metadata block that the device renders below the title, but stock CW + this fork never populated it — the subtitle existed in Calibre and never made it to the device.

`get_subtitle(book)` looks up a Calibre custom column labeled `subtitle`, reads the value off `book.custom_column_N`, and returns the string (or empty when no column or no value). `get_metadata` includes `"Subtitle": get_subtitle(book)` so every sync entry carries the key.

The upstream patch had three null-handling bugs (`.all()[0]` IndexError on missing column, unreachable else branch, TypeError on None attribute). Rewritten with explicit empty-result handling at every fork. 8 RED→GREEN tests in `tests/unit/test_kobo_subtitle_custom_column.py` cover all 6 branches plus metadata-dict integration. 202 adjacent kobo tests green.

Credit: @dotknott in janeczku/calibre-web#3358.
@new-usemame
Copy link
Copy Markdown

Backported into Calibre-Web-NextGen v4.0.99 (commit 44a32bf) — docker pull ghcr.io/new-usemame/calibre-web-nextgen:v4.0.99. Kobo devices now receive the Subtitle from a Calibre custom column labeled subtitle. Rewrote the helper for empty-result safety (no custom column → empty string instead of IndexError).

Heads-up for stock-CW users: this build is CWA-derived, so it adds auto-ingest + kepubify + KOReader sync on top of plain calibre-web.

Thanks @dotknott for the original PR.

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.

4 participants