Match scanned files when the on-disk name drops "The" or author credentials - #784
Match scanned files when the on-disk name drops "The" or author credentials#784dny238 wants to merge 2 commits into
Conversation
…ntials
The per-audiobook scan (ScanFileDiscovery) only linked a file when the
filename contained the full library title or the path contained the full
author. Files whose folder/name dropped a leading article ("Language of
Emotions" vs "The Language of Emotions") or whose author folder dropped
post-nominal credentials/initials ("Karla McLaren" vs "M.Ed. Karla
McLaren", "John Gottman" vs "John M. Gottman PhD") were never matched, so
the file sat on disk unlinked and Scan reported nothing.
Adds tolerant, token-based matching on top of the existing exact checks
(purely additive — prior matches are unchanged): titles are compared with
leading articles/subtitles normalized away, authors with honorifics and
single-letter initials dropped, using order-independent token-subset
comparison. Scoped to the audiobook's own scan folder, so leniency is safe.
Adds ScanFileDiscoveryMatchTests covering the article/credential/subtitle
cases plus a negative (unrelated file) and the exact-match baseline.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Worth flagging up front: this file is rewritten on #717. I built your branch and ran it against its own base (
The first row is a new misattribution, and it also moves The mechanism for the first is Then I built the two shapes your description is about, to check what the change buys:
Both already work on canary, so on these two shapes the tolerant matching isn't adding recall. But the second only works on canary because of the author arm: the title arm needs the full recorded title as a substring and That's the part I'd flag as worth keeping. Your So once #717 removes the author arm, article-dropped names lose the thing currently carrying them, and the title half of this is what replaces it. It's the author half — whole-path, initials stripped — that produces the misattributions above, and dropping it doesn't cost either shape I tested. Repro, if it's useful — from listenarr-testdata: It generates the library, drives a real container, and exits non-zero if the scan claims a file belonging to another book. Happy to run it against any revision you push. |
Review (@m4bard, Listenarrs#784) measured that the author arm caused misattributions: NormalizeAuthor dropped single-letter initials so "M. R. James" collapsed to {james} and subset-matched against the whole path, linking unrelated files that merely shared an author's shelf (Henry James' "The Turn of the Screw" attributed to M. R. James' "Ghost Stories of an Antiquary"). Remove the author fallback entirely and tighten the title rule to strict token-set equality after article/punctuation normalization. This keeps the case this PR targets — on-disk names that only drop a leading "The" (and is what carries article-dropped names once Listenarrs#717 removes the pre-existing author arm) — without attributing files on title alone-less grounds. Adds a regression test for the cross-book/shared-surname case. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Ran the harness against Same setup as last time. One book added,
Your own shapes, same build:
You can run this yourself rather than waiting on me: git clone https://github.com/m4bard/listenarr-testdata && cd listenarr-testdata
python3 -m venv .venv && .venv/bin/pip install -e .
./tools/vet-against.sh \
--repo https://github.com/dny238/Listenarr.git --branch fix/scan-file-match-tolerant \
--tool attribution \
--asin B004FOLXEO --layout author-title \
--only-asin B004FOLXEO,B01ATTZF38,B0C6FJ6L34That clones your branch, builds it, generates a library holding those three books, scans, and exits non-zero if the scan claimed a file belonging to another book. It needs podman or docker, plus ffmpeg and curl. The three ASINs are the M. R. James, Henry James and James M. Barrie books from the table, which are useful together because the names overlap. Anything in |
|
Thanks for the thorough repro — the Pushed 0ac2326: removed the author arm entirely and tightened the title rule to strict token-set equality after article/punctuation normalization (no more either-way subset). So the tolerant path now only fires when the on-disk name equals the recorded title modulo a leading article — e.g. I've left the pre-existing Happy to run your |
|
#717 replaces the old broad scan matcher with ownership/stable-identifier/book-boundary attribution and incorporates the #766/#765 author-overmatch fix. The tolerance in this PR (leading articles, credentials/initials, token-subset matching) is still additional behavior and is not superseded. Please rebase on #717 and add the tolerance inside the new book-boundary matching rules rather than reintroducing broad path matching. |
|
@m4bard thanks for re-running your harness against the reworked branch — good to have it confirmed that the misattributions are gone while the real-world cases still link. @therobbiedavis understood — I'll rebase this on #717 and add the tolerance (leading articles, credentials/initials, title token-set equality) inside the new book-boundary matching rules rather than reintroducing broad path matching. I'll wait for #717 to merge so I'm folding it into the final rules. The tolerance is title-only |
Problem
The per-audiobook filesystem scan (
ScanFileDiscovery.FindMatchingAudioFiles) links a file to the book only when the filename contains the full library title or the path contains the full author string (case-insensitive substring). That misses very common real-world naming:Language of Emotions.m4bfor the book The Language of Emotions.Karla McLaren\for author M.Ed. Karla McLaren, orJohn M. Gottman\vs library authorJohn Gottman **PhD**.Developing Mind\for The Developing Mind, Third Edition.In these cases the audio file sits on disk but the scan matches nothing, so the book stays fileless and Scan Folder appears to do nothing even though the file is right there.
Fix
Adds tolerant, token-based matching on top of the existing exact checks — purely additive, so any file that matched before still matches:
the/a/an) and punctuation/subtitles normalized away.PhD,MD,M.Ed.,CFP,Jr, …) and single-letter initials dropped.Matching is scoped to the audiobook's own scan folder (
scanRoot = audiobook.BasePath), so the extra leniency can't pull in unrelated books.Tests
New
ScanFileDiscoveryMatchTestscovering: exact-title baseline (unchanged), dropped leading "The", author-with-credentials, author-with-middle-initial, title-with-subtitle vs base-title folder, and a negative case (unrelated file must not match).dotnet buildclean (0 warnings)🤖 Generated with Claude Code