Skip to content

Import total pages from calibre on sync#407

Open
ShaidarHaran93 wants to merge 1 commit into
masonfox:developfrom
ShaidarHaran93:develop
Open

Import total pages from calibre on sync#407
ShaidarHaran93 wants to merge 1 commit into
masonfox:developfrom
ShaidarHaran93:develop

Conversation

@ShaidarHaran93

@ShaidarHaran93 ShaidarHaran93 commented Mar 21, 2026

Copy link
Copy Markdown

Hi, I found out about this project yesterday. I have been setting it up today and trying to migrate my data from Excel (12+ years of readings)

One of the pain points I found is that for each book I had to add the total pages number manually which was quite the chore because I had to go to Calibre to look for it.
I had been estimating the pages for years with the Count Pages plugin but while investigating how to add this feature, I found out Calibre added a new table books_pages_link last December which contains the data (you have to add the column on the calibre list view so it does create and populate the new table).

What this PR does

  • Adds a total_pages field to CalibreBook interface.
  • On each of the queries that return that interface.
    • Checks that the table exists.
    • Pulls the page number into the new field.
  • On the syncCalibreLibrary function, when mapping the NewBook object, it maps totalPages from the calibreBook if it exists.

⚠️It does overwrite any value changed manually every time it syncs from Calibre, but if I understood correctly, Calibre's DB is the source of truth so this is not an issue.

I ran the tests and also did a quick check with a copy of my library.

Closes #316

@masonfox

masonfox commented Mar 29, 2026

Copy link
Copy Markdown
Owner

@ShaidarHaran93, thanks for opening this PR! I apologize for the delay, but will take a look at this soon! Cheers!

@masonfox masonfox self-requested a review as a code owner April 12, 2026 15:12
@masonfox

Copy link
Copy Markdown
Owner

I'm so sorry on the delay here, @ShaidarHaran93. I'm conflicted with how to pursue this with respect to #376... 😢 I think it's fine, but will take a closer look tomorrow!

@masonfox

Copy link
Copy Markdown
Owner

@ShaidarHaran93, I'm not sure why, but when I enabled this in Calibre, several of my books didn't calculate pages correctly and produced Error in the UI column. When these error states synced over, it ended up setting the page count to -2 in Tome, which would be problematic for progress log logic 😞. Let me see how that's showing up in Calibre's DB so we can guard against it.

Otherwise, for the books it did correctly identify, it was great! 🙌

I think the only other edge case I can think of write now is how this will possibly negatively effect existing active sessions, especially Reading status, given the risk that it will overwrite the page count, which may negatively affect the sequencing and integrity of progress_logs. Therefore, while I hate to do a ton of joins in the Calibre sync logic, I think we need to protect this from updating the page count on books that're in the Reading status.

I think I'm going to close #316 in favor of this! It's a much better solution than I'd even considered. Thank you! 🙇 And sorry for the delay! Life has been kind of crazy lately, so thanks for the patience! ❤️

@ShaidarHaran93

Copy link
Copy Markdown
Author

I have had books that have incorrect page numbers (close to 0 when I know for a fact they should be higher) but I didn't get any Errors on my library. I don't know how Calibre actually does the calculation but maybe it is an issue with some formats (most of mine are epubs/mobi/azw with a few cbr/cbz comics in). I can say that when it works it is pretty much spot on based on checking some of the books vs their official page count on Amazon or Goodreads.

About the edge case, have you considered adding a flag to the books table? It would let you avoid having to do joins. Something like updateable or locked that can get activated when a reading is started or when the user modifies some book metadata by hand and locks the basic book metadata from being updated by the calibre sync (or future others if you end up pulling metadata from other sources).

As for how it affects #376 I think decoupling internally from the Calibre structure can be good for people who don't use Calibre and don't want to use it, but when using Calibre this should be part of the sync (or at least the initial sync), in order to avoid having to manually input data that is already available.

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.

Automatic page count fetcher

2 participants