fix(hardcover): search "Title: A Novel" as the title, not the full string (#1729)

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)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## 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.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: ali <9556797+hongtron@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-11-19 18:54:47 -05:00
1 parent 9b89857923
commit a1a197020a
2 files changed
+42 -10

No files matched your search

+18 -10
View File
@@ -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():
@@ -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")