Skip to content

Fix LazyLibrarian request resolution: pick the real book, not summaries; fail loudly on unresolvable IDs#11

Open
vomZwinghof wants to merge 1 commit into
zamnzim:mainfrom
vomZwinghof:fix/request-resolution
Open

Fix LazyLibrarian request resolution: pick the real book, not summaries; fail loudly on unresolvable IDs#11
vomZwinghof wants to merge 1 commit into
zamnzim:mainfrom
vomZwinghof:fix/request-resolution

Conversation

@vomZwinghof

Copy link
Copy Markdown

Fix LazyLibrarian request resolution: pick the real book, not summaries; fail loudly on unresolvable IDs

Problem

When a request is handed to a LazyLibrarian backend, the wrong book is frequently added — or the request silently fails — because of how the BookID is resolved in lazylibrarian.py:

  1. Summaries / study guides win. search_books(...) / add_book take the first findBook result. For many popular titles LazyLibrarian (GoodReads) returns cash-grab "Book Summary of …", "Study Guide …", "Trivia: …" editions before the real novel, so the summary gets added and downloaded instead of the book.

    • Reproduced: requesting “The Martian” by Andy Weir resolves to “Book Summary of THE MARTIAN by Andy Weir” (different author/edition).
  2. Silent failure on non-LazyLibrarian IDs. When findBook returns nothing, the request flow falls back to the Open Library work id (OL…W) and passes it straight to addBook. LazyLibrarian doesn’t recognise it, returns OK, and no book is ever created — the request sits on “processing” forever with no error.

  3. ISBN lookup can hang the request. lookup_by_isbn calls LazyLibrarian’s searchItem, which can return HTTP 500; the unhandled exception propagates and the request errors out instead of falling back to a name search.

Fix (scoped to lazylibrarian.py)

  • Add a small filter/ranking helper _rank() used by search_books: it drops obvious non-book editions (Summary / Study Guide / Trivia / Instaread / Blinkist / …) and sorts the rest by title+author overlap with the query, so [0] is the best real match.
  • add_book now resolves the BookID defensively: it trusts an incoming id only if it’s a plausible numeric LazyLibrarian/GoodReads id and the title isn’t a junk edition; otherwise it re-resolves via search_books. If no valid numeric id can be found (e.g. only an OL…W id is available) it raises ValueError — surfacing a real error instead of silently adding nothing.
  • lookup_by_isbn wraps the searchItem call in try/except and returns [] on requests.exceptions.RequestException, so callers cleanly fall back to name search.

Result-mapping for findBook/searchItem is de-duplicated into _map_book. No behaviour change for already-correct requests — only the resolution path is hardened.

Testing

Verified end-to-end against a live LazyLibrarian + Calibre-Web setup:

  • Request “The Martian” → resolves to the real novel (GoodReads id 18007564) → grabbed via NZBGet → imported as EPUB (previously resolved to the Book Summary edition).
  • add_book({... "foreignBookId": "OL20823239W"}) with no findBook match → raises ValueError (request shows error) instead of silently succeeding.
  • ISBN searchItem returning HTTP 500 → logged warning + [], request falls back to name search.
  • Unit checks: _is_junk_title("Book Summary of THE MARTIAN")True; _looks_like_ll_id("18007564")True; _looks_like_ll_id("OL20823239W")False.

Notes

  • Change is intentionally limited to the LazyLibrarian client. The Readarr client (readarr.py) uses the same results[0] pattern and could get the same _rank treatment in a follow-up if desired.
  • The junk-title marker list is deliberately conservative; the ranking (title coverage + author hit) does most of the disambiguation, so a title that legitimately contains one of those words still wins on score when it is the best match.

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