From a1a197020af1db78a9e37943b06ace3f0e80ee7f Mon Sep 17 00:00:00 2001 From: ali hong Date: Thu, 19 Nov 2026 17:54:47 -0600 Subject: [PATCH] fix(hardcover): search "Title: A Novel" as the title, not the full string (#1729) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1728 Hardcover stores a lot of books as `Title: A Novel` with `A Novel` as the subtitle. `_compute_search_title` sent those through `_is_probably_series_position`, which treats "A Novel" the same as "Book 1" and returns `None`. The search then falls back to the full title, so the release search sends `Title: A Novel` to Prowlarr, and indexers that require every word find nothing. This splits the check into `_is_series_position` and `_is_genre_descriptor`. The descriptor rules themselves are unchanged. `Series: Book 1` and `Series: A Novel` still return `None`. `Title: A Novel` now returns `Title`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) ## Summary by CodeRabbit * **Bug Fixes** * Book searches now handle descriptive subtitles such as “A Novel” and “A Memoir” more accurately, using the book title rather than subtitle wording when appropriate. * Titles that consist of a series name followed by a descriptive subtitle are no longer treated as book titles. Co-authored-by: ali <9556797+hongtron@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- shelfmark/metadata_providers/hardcover.py | 28 ++++++++++++------- tests/metadata/test_hardcover_search_title.py | 24 ++++++++++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/shelfmark/metadata_providers/hardcover.py b/shelfmark/metadata_providers/hardcover.py index a4d73e11..c87ec939 100644 --- a/shelfmark/metadata_providers/hardcover.py +++ b/shelfmark/metadata_providers/hardcover.py @@ -878,15 +878,18 @@ def _build_source_url(slug: str) -> str | None: return f"https://hardcover.app/books/{slug}" if slug else None -def _is_probably_series_position(subtitle: str) -> bool: - normalized = subtitle.strip().lower() - +def _is_series_position(text: str) -> bool: # Common patterns: "Book One", "Book 1", "Part 2", "Volume III", etc. - if re.match( - r"^(book|part|volume|vol\.?|episode)\s+([0-9]+|[ivxlcdm]+|one|two|three|four|five|six|seven|eight|nine|ten)\b", - normalized, - ): - return True + return bool( + re.match( + r"^(book|part|volume|vol\.?|episode)\s+([0-9]+|[ivxlcdm]+|one|two|three|four|five|six|seven|eight|nine|ten)\b", + text.strip().lower(), + ) + ) + + +def _is_genre_descriptor(text: str) -> bool: + normalized = text.strip().lower() # e.g. "A Novel", "An Epic Fantasy", etc. These add noise to indexer queries. if normalized in {"a novel", "a novella", "a story", "a memoir"}: @@ -1035,9 +1038,14 @@ def _compute_search_title( ) if prefix_is_series or subtitle_is_suffix: # "Series: Book 1" names nothing to search for on either side of the colon. - if _is_probably_series_position(suffix): + if _is_series_position(suffix): return None - return suffix if prefix_is_series else prefix + if prefix_is_series: + # "Series: A Novel" names no book either. + return None if _is_genre_descriptor(suffix) else suffix + # "Title: A Novel" only describes the book, so the prefix is the title. + # Returning None here would search the full title, ": A Novel" and all. + return prefix # Last resort: return a cleaned version of the title if we removed noise. if normalized_title and normalized_title.lower() != original_title.lower(): diff --git a/tests/metadata/test_hardcover_search_title.py b/tests/metadata/test_hardcover_search_title.py index 0494007e..dcfc5926 100644 --- a/tests/metadata/test_hardcover_search_title.py +++ b/tests/metadata/test_hardcover_search_title.py @@ -89,6 +89,30 @@ class TestHardcoverComputeSearchTitle: is None ) + @pytest.mark.parametrize( + ("title", "subtitle", "series", "expected"), + [ + # Searched as the full title before, and MAM ANDs every word, so a torrent + # named without the descriptor never matched. + ("The Last Thing He Told Me: A Novel", "A Novel", None, "The Last Thing He Told Me"), + ("Educated: A Memoir", "A Memoir", None, "Educated"), + ( + "No Plan B: A Jack Reacher Novel", + "A Jack Reacher Novel", + "Jack Reacher", + "No Plan B", + ), + ], + ) + def test_a_genre_descriptor_subtitle_leaves_the_prefix(self, title, subtitle, series, expected): + assert _compute_search_title(title, subtitle, series_name=series) == expected + + def test_a_series_followed_by_a_genre_descriptor_names_no_book(self): + assert ( + _compute_search_title("Jack Reacher: A Novel", "A Novel", series_name="Jack Reacher") + is None + ) + def test_strips_series_prefix_when_series_name_available(self): assert ( _compute_search_title("Mistborn: The Final Empire", None, series_name="Mistborn")