Fix LazyLibrarian request resolution: pick the real book, not summaries; fail loudly on unresolvable IDs#11
Open
vomZwinghof wants to merge 1 commit into
Open
Conversation
…es; fail loudly on unresolvable IDs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:Summaries / study guides win.
search_books(...)/add_booktake the firstfindBookresult. 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.Silent failure on non-LazyLibrarian IDs. When
findBookreturns nothing, the request flow falls back to the Open Library work id (OL…W) and passes it straight toaddBook. LazyLibrarian doesn’t recognise it, returns OK, and no book is ever created — the request sits on “processing” forever with no error.ISBN lookup can hang the request.
lookup_by_isbncalls LazyLibrarian’ssearchItem, 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)_rank()used bysearch_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_booknow 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 viasearch_books. If no valid numeric id can be found (e.g. only anOL…Wid is available) it raisesValueError— surfacing a real error instead of silently adding nothing.lookup_by_isbnwraps thesearchItemcall intry/exceptand returns[]onrequests.exceptions.RequestException, so callers cleanly fall back to name search.Result-mapping for
findBook/searchItemis 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:
18007564) → grabbed via NZBGet → imported as EPUB (previously resolved to the Book Summary edition).add_book({... "foreignBookId": "OL20823239W"})with nofindBookmatch → raisesValueError(request shows error) instead of silently succeeding.searchItemreturning HTTP 500 → logged warning +[], request falls back to name search._is_junk_title("Book Summary of THE MARTIAN")→True;_looks_like_ll_id("18007564")→True;_looks_like_ll_id("OL20823239W")→False.Notes
readarr.py) uses the sameresults[0]pattern and could get the same_ranktreatment in a follow-up if desired.