Skip to content

fix(scan): group chapter files indexed as "N of M" into one unmatched-scan item - #845

Open
m4bard wants to merge 1 commit into
Listenarrs:canaryfrom
m4bard:fix/bug4-n-of-m-chapter-stem
Open

fix(scan): group chapter files indexed as "N of M" into one unmatched-scan item#845
m4bard wants to merge 1 commit into
Listenarrs:canaryfrom
m4bard:fix/bug4-n-of-m-chapter-stem

Conversation

@m4bard

@m4bard m4bard commented Aug 20, 2026

Copy link
Copy Markdown

Summary

A chapter-per-file book numbered Title 001 of 006, with no album tag to fall back on, comes back from Library Import as one scan item per file. This strips a trailing N of M index in ExtractTitleStem so those files share a stem and group into one item.

Full write-up, the measurements and the case I deliberately did not touch are in #844.

Changes

Fixed

  • ExtractTitleStem strips a trailing [\s\-_]*\d+\s*of\s*\d+$ before the existing leading-track strip.

The ordering is the part worth reviewing. A file named 001 of 498, with no title in it at all, loses its leading 001 first if these run the other way round. That leaves of 498, which is a different stem in every file and is no longer numeric, so the folder-name fallback at the end never gets the chance to gather them. The comment says so at the call site.

(N) is deliberately untouched. The existing comment explains that plain numeric parens are kept because they distinguish separate books in a series, which is a real tradeoff rather than an oversight, so changing it is a product decision rather than a bug fix. The issue lays out the case for revisiting it, including that the frontend already disagrees with the backend about what (N) means.

Testing

Three tests in UnmatchedScanBackgroundServiceTests:

  • the ordinary case, Jack of Shadows 001 of 004.mp3 and siblings, grouping into one
  • the bare case, 001 of 003.mp3 with no title in the filename, which is the one that fails if the two strips run in the wrong order
  • a negative case holding Jack of Shadows.mp3 and Nine Princes in Amber 2.mp3 apart in one author folder, since "of" between two words is not an index and a trailing number is not a total

Full suite on this branch: 3,032 passed, 0 failed, 125 skipped, against a 3,029 baseline on 03958c15.

Reproduced end to end before and after against ghcr.io/listenarrs/listenarr:canary, using a generated library of nine folders that vary only in filename convention and title tags. On canary two of the nine explode; on a build of this branch notags-n-of-m groups into one item, notags-paren-index is unchanged and still explodes by design, and the other seven stay grouped. So it moves exactly the case it targets and nothing else. The check is public, in the test-data repo linked from the issue.

Notes

The album-tag detail is worth knowing when judging the blast radius. Filenames are grouped first and embedded tags are only consulted when that produced more than one group, and the value compared is album rather than title. Any folder whose files share an album tag was already being rescued by the metadata pass, so this only changes what happens to files carrying no album tag at all.

ExtractTitleStem strips a leading track number and a trailing
Part/CD/Disc/Chapter/pt number, but nothing recognises an "N of M" index.
A book split as "Title 001 of 498.mp3" therefore produces a distinct stem
per file, and BuildStemGroups returns one group per file, so Library
Import asks the operator to identify the same book once per chapter.

Unlike a bare "(N)", this form is not ambiguous with the series marker
the existing comment describes: it carries its own total, so it names a
part of a set rather than one work among several.

The strip runs before the leading-track strip. A file named
"001 of 498.mp3" would otherwise lose its leading "001 " first and be
left as "of 498", which is both different in every file and no longer
numeric, so it would never reach the folder-name fallback that exists to
group exactly this case.

Titles are unaffected where the pattern does not fit: "of" needs digits
on both sides, so "Jack of Shadows.mp3" keeps its stem, and a trailing
plain number still separates two works in one folder.
@m4bard
m4bard requested a review from a team August 20, 2026 17:36
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