Skip to content

fix: use ebookProgress field for ebook reading progress#164

Open
rohit-purandare wants to merge 10 commits intomainfrom
fix/ebook-progress
Open

fix: use ebookProgress field for ebook reading progress#164
rohit-purandare wants to merge 10 commits intomainfrom
fix/ebook-progress

Conversation

@rohit-purandare
Copy link
Copy Markdown
Owner

Audiobookshelf returns ebook progress in a separate ebookProgress field while the progress field is always 0 for ebooks. Prefer ebookProgress when available, falling back to progress for audiobooks.

Audiobookshelf returns ebook progress in a separate ebookProgress
field while the progress field is always 0 for ebooks. Prefer
ebookProgress when available, falling back to progress for audiobooks.
Fixes issue where books finished naturally in Audiobookshelf were not
updating to 100% completion in Hardcover.

Root cause: extractFinishedFlag() only checked is_finished boolean but
ignored finished_at timestamp. When users finish books naturally by
listening to the end, Audiobookshelf sets finished_at but is_finished
may remain false.

Changes:
- Check finished_at timestamp in addition to is_finished flag
- Return null (not false) when no completion indicators found, allowing
  position-based and percentage-based detection to proceed
- Reduce time-remaining threshold from 120s to 60s for audiobooks
- Add aggressive 98% completion threshold for all formats
- Fix parameter name mismatch in isBookComplete() method

Tests:
- Add comprehensive test suite with 28 tests covering all scenarios
- All existing tests still pass (127 total)
- Includes integration test reproducing exact bug scenario
…ress

The ?? operator doesn't fall through when ebookProgress is 0 (not nullish),
causing all audiobooks to report 0% progress. Using || correctly falls
through to the progress field when ebookProgress is 0 (falsy).
Remove stale files that were accidentally left in the repo:
DUPLICATE_MATCHING_FIX.md, SECURITY_NOTE.md,
TESTING_WANT_TO_READ_STATUS_UPDATE.md, run-all-tests.sh,
test-release-targeting.txt, test-signing.md, wait-and-test.sh
Two-stage title/author matches store the book ID at match.book.id when
the book isn't in the user's library, but sync-manager only checked
match.userBook?.book?.id (undefined when userBook is null). Also fix
edition ID being cached as undefined since _cacheSuccessfulMatch used
bestMatch.id instead of bestMatch.edition.id for two-stage results.
…and format

Audiobookshelf uses mediaType 'book' for both audiobooks and ebooks.
Previously this always resolved to 'audiobook', causing ebooks to match
audiobook editions and report wrong progress (e.g. 62.5% → 0.0%).

Now check media.ebookFile and media.audioFiles to distinguish ebooks
from audiobooks. Also use the correct progress field per item type:
ebookProgress for ebooks, progress for audiobooks.
The log used edition.reading_format?.format which is only present on
raw Hardcover editions. Two-stage title/author matches flatten this to
edition.format. Fall back to edition.format so the log isn't undefined.
…ch matches

The book ID lookup was gated by _needsBookIdLookup which was never set
for title_author_two_stage matches, causing "Missing required IDs" errors
when adding books like the LOTR trilogy to the library. Now the lookup
fires whenever bookId is missing and an editionId is available.

Also migrates ISBN search from the editions GraphQL query to the search
API endpoint for consistency, adds edition ID resolution for ISBN search
matches, and centralizes search result parsing into _parseSearchResults.
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