Repository navigation
fix(scanner): read audiobook titles, part order, chapters, credits, and series correctly from tags - #4203
Conversation
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 45 seconds. View limit details
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (2)
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9641d02472
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if len(b.Narrators) > 0 { | ||
| b.Narrator = b.Narrators[0] |
There was a problem hiding this comment.
Compare complete credit sets before deduplicating recordings
When two recordings have the same title, year, and sufficiently close durations but different narrator ensembles sharing the first narrator, assigning only the first name here makes findAudiobookDuplicate treat them as identical. That function still passes only book.Author and book.Narrator to audiobookDuplicateCandidateSQL, whose joins merely check that those people exist. For example, Reader One; Reader Two now matches an edition narrated only by Reader One, whereas their unsplit tags previously kept them distinct. The resulting shared content ID combines the editions' files and lets upsertAudiobookPeople replace one edition's credits with the other's. Validate the complete author and narrator sets before accepting a duplicate.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in fcf7257. The duplicate check still uses the first author and narrator to find candidates, then requires the candidate's full author and narrator set to match the book's credits before it reuses that item. "Reader One; Reader Two" no longer merges into an edition narrated only by Reader One.
There was a problem hiding this comment.
Refined in 13eca3a: a candidate now has to carry every tagged author and narrator but may have more, so a provider-matched book keeps its item when its folder is renamed, and editions sharing only the first narrator still stay separate.
| }) | ||
|
|
||
| book := &parsedAudiobook{} | ||
| return parseAudiobookParts(ctx, ffprobePath, folderPath, audioFiles) |
There was a problem hiding this comment.
Existing matched books never receive the corrected metadata
Previously indexed, matched audiobooks with unchanged files bypass parseAudiobookParts, so upgrades do not correct their metadata. Invalidate the unchanged check for books indexed before this parser version so they are reconciled once.
Prompt for LLM
File internal/scanner/audiobook.go, line 168:
Existing matched books never receive the corrected metadata
Previously indexed, matched audiobooks with unchanged files bypass `parseAudiobookParts`, so upgrading does not correct their titles, ordering, chapters, credits, or series. Invalidate the unchanged check for books indexed before this parser version so they are reconciled once.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Not changing this here, on purpose. The PR's Approach section explains why: today, reprocessing a provider-matched book resets its year and credits to the tag values. Forcing every existing book through the scanner would undo provider matches across the whole library. A one-time rebuild can follow once the separate change that stops that overwrite lands. Until then, books pick up these fixes when their files change.
There was a problem hiding this comment.
That tradeoff makes sense. I withdraw the suggestion to force a one-time rebuild in this PR: doing so could overwrite provider-matched years and credits across existing libraries.
The limitation is documented: unchanged books will not receive the parser fixes until their files change. A one-time rebuild can be considered after reprocessing preserves provider metadata.
| if len(audioFiles) > 1 && strings.TrimSpace(bookTags["album"]) != "" { | ||
| titles := make([]string, len(parts)) | ||
| for i, p := range parts { | ||
| titles[i] = p.tags["title"] | ||
| } | ||
| book.Files = append(book.Files, parsedAudiobookFile{ | ||
| Path: path, | ||
| Chapters: []ChapterInfo{{ | ||
| if partTitlesNameParts(titles) { | ||
| book.Title = bookTags["album"] |
There was a problem hiding this comment.
Chapter titles remain book titles when the album tag is absent
The first chapter title blocks the filesystem fallback and provider matching. When the title names a part and bookTags["album"] is empty, clear the title before applying the fallback.
Prompt for LLM
File internal/scanner/audiobook.go, lines 259-265:
Chapter titles remain book titles when the album tag is absent
A multi-file book with chapter-style title tags but no album tag keeps the first chapter as its book title, preventing the filesystem fallback and provider matching. When the title names a part and no album is available, clear it before applying the filesystem fallback.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Fixed in fcf7257. When the part titles name the parts and there is no album tag, the scanner clears the title, so the folder-name fallback supplies it.
There was a problem hiding this comment.
Thanks for the update. Clearing the part-style title when the album tag is absent should allow the folder-name fallback to supply the book title. I haven’t independently verified the commit.
| if len(parts) == 0 { | ||
| return nil, fmt.Errorf("audiobook folder %s: ffprobe rejected every audio file (%s)", folderPath, strings.Join(book.UnreadableParts, ", ")) |
There was a problem hiding this comment.
Books with no readable parts retain playable file records
The error prevents upsertAudiobookPresentationTx from marking rejected files missing, while the missing-file sweep still sees them on disk, leaving the damaged recording advertised as playable. Retire rejected file rows even when no readable part remains.
Prompt for LLM
File internal/scanner/audiobook.go, lines 229-230:
Books with no readable parts retain playable file records
When every part of an already indexed book is rejected, this error returns before `upsertAudiobookPresentationTx` can mark the existing file rows missing. The missing-file sweep also sees those paths on disk, leaving the damaged recording advertised as playable indefinitely; retire rejected rows even when no readable part remains.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Fixed in fcf7257. When ffprobe rejects every file in a book, the parse error now carries those paths and the scanner marks their rows missing, so the book is no longer offered as playable. The folder still counts as a failed scan.
There was a problem hiding this comment.
Thanks for the update. The reported fix addresses the original concern: rejected file rows are marked missing even when no readable parts remain, while the folder still counts as a failed scan.
I haven’t independently verified commit fcf7257f7f.
| book.Files = make([]parsedAudiobookFile, len(parts)) | ||
| for i, p := range parts { | ||
| file := p.file | ||
| if len(parts) > 1 && len(file.Chapters) == 0 { |
There was a problem hiding this comment.
A multipart book loses its chapter when only one part is readable
The surviving file receives no synthesized chapter because the condition counts readable parts rather than the original files. Use the audioFiles count so the surviving part retains its filename chapter.
Prompt for LLM
File internal/scanner/audiobook.go, line 273:
A multipart book loses its chapter when only one part is readable
When a multipart book has only one readable part, the remaining file receives no synthesized chapter because the condition checks the number of readable parts rather than the original audio files. Use the original multipart count so the surviving part still has its filename chapter.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Fixed in fcf7257. The chapter rule now counts the book's audio files, so a multi-file book with one readable part keeps that part's filename chapter.
There was a problem hiding this comment.
Thanks for the update. Counting the original audio files addresses the reported case: the one readable part retains its filename-based chapter.
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 9641d02472
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
| for _, group := range strings.Split(raw, ";") { | ||
| for _, joined := range splitCreditPieces(group, audiobookCreditConjunctionRE) { | ||
| for _, name := range splitCreditPieces(joined, audiobookCreditCommaRE) { |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Security: Cap audiobook credit fan-out before database writes
Condition: a malicious audiobook must be placed in an enabled, configured library and scanned. splitAudiobookCredits treats every semicolon-delimited tag segment as a credit with no count or length cap; the write path then calls FindOrCreate once per credit, and each new name commits a durable people row. One crafted author or narrator tag can therefore drive thousands of serial database transactions and persistent row growth during the default daily scan. Cap tag bytes and credits per role before building or writing the slice; deduplication stops repeated, not unique, names.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in fcf7257. One author or narrator tag now yields at most 20 credits, and a name longer than 200 bytes is dropped. A unit test covers the cap.
…nd series from tags correctly
- A multi-file book whose title tags name the parts ("Chapter 01") takes
its title from the album tag.
- Parts follow disc and track tags when every part has distinct numbers;
otherwise natural filename order as before.
- Parts of a multi-file book keep their embedded chapters; parts without
them still get one chapter named after the file.
- A part ffprobe rejects as damaged is left out with a warning and counted
in the scan summary; the book is indexed from its readable parts. The
rejection is remembered for the process so unchanged rescans neither
probe it again nor rebuild the book. A previously indexed part that turns
unreadable is retired.
- Author and narrator tags naming several people split into separate
credits on ";" and, when every piece is a full name, on "&", "and", and ",".
- Series come also from MP4 movement atoms (read from the file, since
ffprobe does not expose them) and from a grouping tag with a position;
positions such as "Book 3", "#3", "Vol. 3", and "III" parse.
- The long description (synopsis) wins over the short one.
- Genre values containing "/" or ";" split only on those, keeping
"Mystery, Thriller & Suspense" whole.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rom review - Duplicate detection compares the full author and narrator sets, not only the first of each, so editions sharing a lead narrator stay separate. - One author or narrator tag yields at most 20 credits of up to 200 bytes. - A multi-file book whose part titles name the parts and that has no album tag takes its title from the folder instead of the first part. - A multi-file book with one readable part keeps that part's file chapter. - When ffprobe rejects every file of an indexed book, its rows are marked missing instead of staying playable. Co-Authored-By: Claude Opus 5.5 <[email protected]>
9641d02 to
fcf7257
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
| if len(audioFiles) > 1 { | ||
| titles := make([]string, len(parts)) | ||
| for i, p := range parts { | ||
| titles[i] = p.tags["title"] | ||
| } | ||
| // A part title never names the book. Without an album tag the | ||
| // filesystem fallback below supplies the title. | ||
| if partTitlesNameParts(titles) { | ||
| book.Title = strings.TrimSpace(bookTags["album"]) |
There was a problem hiding this comment.
Missing part titles discard a valid book title
Revises an earlier Kody suggestion on internal/scanner/audiobook.go:259 (2026-11-14 22:57 UTC).
A missing title on a later part can replace a valid book title with the album or folder name, causing provider matching to fail. Ignore missing tags when comparing titles in partTitlesNameParts, while retaining the track-style title check.
Prompt for LLM
File internal/scanner/audiobook.go, lines 260-268:
**Revises an earlier Kody suggestion** on `internal/scanner/audiobook.go:259` (2026-11-14 22:57 UTC).
Missing part titles discard a valid book title
A multipart book with a valid first-file title and a missing title on a later file is classified as having part titles, so its valid title is replaced by the album or folder name and provider matching can fail. Ignore missing title tags when comparing part titles, while retaining the track-style title check.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Fixed in bd3f5bc. Parts without a title tag are now ignored when comparing part titles, so one untitled part no longer swaps a valid book title for the album. The track-title check stays. A test case covers it.
There was a problem hiding this comment.
Thanks for the update. Ignoring missing titles while retaining the track-title check addresses the reported issue, and the added test covers the regression. I haven’t independently verified the commit or test.
| return | ||
| } | ||
| if _, err := s.fileRepo.Pool().Exec(ctx, ` | ||
| UPDATE media_files SET missing_since = COALESCE(missing_since, NOW()) |
There was a problem hiding this comment.
Probe rejection can persistently mark transiently inaccessible files missing
A transient probe or storage failure can cause media_files.missing_since to be set persistently. Inspect ffprobe diagnostics and perform bounded, cancellation-aware readability checks at both ends of each file; leave files retryable if checks fail or cannot complete.
Kody rule violation: Require evidence of damage before marking media unreadable
Prompt for LLM
File internal/scanner/audiobook_scan.go, line 914:
Probe rejection can persistently mark transiently inaccessible files missing
Do not persistently mark these files missing solely because ffprobe rejected them. First distinguish confirmed media damage from transient probe or storage failures: inspect the probe diagnostics and perform bounded, cancellation-aware readability checks at both the beginning and end of each file. Leave files retryable when those checks fail or cannot complete.
Kody rule violation: [Require evidence of damage before marking media unreadable](https://kodus.siloserver.org/settings/code-review/1247142351/kody-rules/de79c4d2-dfc0-4979-b481-a0697fbb3805?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
No change; the rejection check already does this. A part is skipped and later retired only when IsProbeRejection says ffprobe rejected its content. That check first searches ffprobe's stderr for OS access errors (I/O error, permission denied, stale handle, timeout, and so on). It then runs a bounded, cancellation-aware read at the start and end of the file. Either finding an access problem, a busy check, a canceled context, a missing binary, or a signal makes it answer false. In those cases the scanner fails the folder for this scan and leaves every row as it was. The movie scanner uses the same check before it sets probe_failed_at.
There was a problem hiding this comment.
You’re right; I missed the existing guard. The PR diff shows that parseAudiobookParts calls IsProbeRejection before adding a newly rejected part to UnreadableParts. When the check returns false, parsing returns an error instead, so that failure does not lead to retirement.
Given the safeguards you described in IsProbeRejection, the original suggestion is redundant. I withdraw the finding; no change is needed for it.
| // editions, so the whole credit set must agree. | ||
| desired := book.credits() | ||
| for _, candidateID := range candidates { | ||
| people, err := s.itemRepo.GetPeople(ctx, candidateID) |
There was a problem hiding this comment.
Duplicate detection reads credits once per candidate
Calling GetPeople for each matching candidate makes database requests scale with the number of candidates. Fetch author and narrator credits for deduplicated candidate IDs in bounded batches before comparing them.
Kody rule violation: Batch scoped Go lookups and bound dependency fan-out
Prompt for LLM
File internal/scanner/audiobook_scan.go, line 1184:
Duplicate detection reads credits once per candidate
Fetch author and narrator credits for the deduplicated candidate IDs in bounded batches before comparing candidates. The current per-candidate lookup adds one database request for every matching title, so duplicate detection scales its dependency calls with the candidate count.
Kody rule violation: [Batch scoped Go lookups and bound dependency fan\-out](https://kodus.siloserver.org/settings/code-review/1247142351/kody-rules/d2a64d9a-568c-46c2-9fa4-ad93c54ef90e?teamId=ba9922fc-c0ea-4cf8-87bb-9d4f42ffc73e)
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Fixed in bd3f5bc. The candidates' author and narrator credits now load in one query (content_id = ANY), and the comparison runs over that map.
There was a problem hiding this comment.
Thanks for the update. Loading candidate credits in one query addresses the per-candidate database lookup concern. I haven’t independently verified commit bd3f5bc926.
| for _, candidateID := range candidates { | ||
| people, err := s.itemRepo.GetPeople(ctx, candidateID) |
There was a problem hiding this comment.
Duplicate detection queries credits separately for every candidate
Sequential GetPeople calls can add up to 25 database round trips for each newly indexed book with similar editions. Fetch credits for all candidate IDs in one query before comparing them.
Prompt for LLM
File internal/scanner/audiobook_scan.go, lines 1183-1184:
Duplicate detection queries credits separately for every candidate
Each title-matching candidate triggers a separate sequential `GetPeople` database query, adding up to 25 round trips for each newly indexed book with similar editions. Fetch credits for all candidate IDs in one query before comparing them.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Fixed in bd3f5bc with the same change: one query for all candidates instead of one GetPeople call per candidate.
There was a problem hiding this comment.
Thanks for the update. The batched query in bd3f5bc926 addresses the reported per-candidate query concern. I haven’t independently verified the commit.
- A part without a title tag no longer makes a book's part titles look different, so it cannot replace a valid book title with the album. - Duplicate detection loads the candidates' author and narrator credits in one query instead of one per candidate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Duplicate detection required the candidate's author and narrator set to equal the book's tag credits. A provider match stores the provider's fuller credits, so renaming a matched book's folder created a new item and dropped its progress. Every tagged credit must now appear on the candidate, which may have more; editions that share only the first narrator still stay separate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
| } | ||
| desired := book.credits() | ||
| for _, candidateID := range candidates { | ||
| if audiobookCreditsContain(credits[candidateID], desired) { |
There was a problem hiding this comment.
Credit subset matching merges different audiobook editions
Recordings with a shared lead narrator and matching title, year, and duration can share a content ID, playback progress, and metadata. Before audiobookCreditsContain accepts a credit superset, distinguish a folder move from a separate recording.
Prompt for LLM
File internal/scanner/audiobook_scan.go, line 1190:
Credit subset matching merges different audiobook editions
A recording tagged with only a shared lead narrator now matches a different edition with additional narrators when the title, year, and duration also match, merging both folders into one content ID and sharing playback progress and metadata. Distinguish an actual folder move from a separate recording before accepting a credit superset.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Fixed in 732f5c2. Credit containment is now only the first test. An existing item is reused only when none of its indexed files in this library is still on disk, which tells a moved folder from a second copy or another edition. A stat error other than not-exist counts as present, so a storage problem cannot cause a merge. The rule is now: a moved or renamed folder keeps its item, and two copies on disk are two items, whatever order the scan reaches them in. Unit cases cover a move with provider credits, a second copy, and an unreadable old path. A new DB test (TestScanAudiobookSecondCopyIsItsOwnItemDB) covers two copies, and the existing rename DB test now adds a provider narrator before the rename.
There was a problem hiding this comment.
Thanks for the update. The reported fix addresses the original concern: credit containment alone no longer causes an existing item to be reused when its indexed files are still on disk. The conservative handling of stat errors also helps prevent merges during storage problems.
The described tests cover the key cases: a rename with provider-added credits, a second copy, and an inaccessible old path. I haven’t independently verified commit 732f5c22fd or run the tests.
| } | ||
| desired := book.credits() | ||
| for _, candidateID := range candidates { | ||
| if audiobookCreditsContain(credits[candidateID], desired) { |
There was a problem hiding this comment.
Renamed books lose extra provider credits after a superset match
upsertAudiobookPeople replaces extra provider credits with the shorter tag set after a renamed book matches a superset, unless crew is locked. Preserve existing provider credits when reusing an item through a superset match.
Prompt for LLM
File internal/scanner/audiobook_scan.go, line 1190:
Renamed books lose extra provider credits after a superset match
When a renamed book matches a candidate with extra provider credits, `upsertAudiobookPeople` subsequently replaces the full credit set with the shorter tag set unless crew is locked, deleting the provider credits this change intends to preserve. Preserve existing provider credits when reusing an item through a superset match.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Not changing this here. Replacing a matched book's provider credits with the tag set is main's existing behavior for any changed folder, not something this PR introduces. Sibling PR #4220 fixes it: the scanner stops replacing credits on a provider-matched book.
There was a problem hiding this comment.
Understood. I’ll withdraw the suggestion for this PR: replacing provider credits is existing behavior, and sibling PR #4220 addresses it.
…er is gone A candidate with every tagged credit could still be a second copy or another edition that is on disk. Duplicate detection now reuses an item only when none of its indexed files in the library still exists, so a moved or renamed folder keeps its item and progress while two copies on disk are two items, whatever order the scan reaches them in. A stat error other than not-exist counts as present. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 732f5c22fd
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
| func rememberRejectedAudiobookPart(path string, size int64, modTime time.Time) { | ||
| rejectedAudiobookParts.Lock() | ||
| defer rejectedAudiobookParts.Unlock() | ||
| rejectedAudiobookParts.byPath[path] = rejectedAudiobookPart{size: size, modTime: modTime} |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Security: Bound rejected audiobook part caching
Condition: an untrusted import source must be able to add files to an enabled audiobook library. Every distinct file that ffprobe rejects is inserted into this process-global map, and no removal path exists; deleted or renamed files remain referenced until restart. By cycling batches of uniquely named invalid audio files, that source can grow the server heap across the default daily scans until the process is OOM-killed. The prior credit-count cap does not cover this fresh path-based accumulation. Bound the cache and evict entries when paths disappear or age out.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c191111. The list now holds at most 4096 files. When it is full, a new file drops one arbitrary entry instead of growing the map, and the only cost is one more probe of the dropped file. There is no LRU and no sweeper. A unit test fills the list past the cap and checks its size and that the newest entry is kept.
The process-wide list of files ffprobe rejected now holds at most 4096 entries. When full, a new file drops an arbitrary entry, which only costs one more probe of that file, so files written into a library cannot grow the list without bound. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
| if _, known := byPath[path]; !known && len(byPath) >= maxRejectedAudiobookParts { | ||
| for old := range byPath { | ||
| delete(byPath, old) | ||
| break |
There was a problem hiding this comment.
Eviction repeatedly reprobes unchanged audiobook folders
Libraries with more than 4096 rejected files repeatedly run ffprobe on rejected and readable parts because unchanged folders fail audiobookFolderShouldSkip. Persist rejection fingerprints or retain enough per-folder state to skip unchanged rejected parts without unbounded process memory.
Prompt for LLM
File internal/scanner/audiobook_tags.go, lines 264-267:
Eviction repeatedly reprobes unchanged audiobook folders
Evicting rejected parts makes their unchanged folders fail `audiobookFolderShouldSkip`, so libraries with more than 4096 rejected files repeatedly run ffprobe on both rejected and readable parts of affected books on subsequent scans. Persist rejection fingerprints or otherwise retain enough per-folder state to skip unchanged rejected parts without unbounded process memory.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Declining this one. The cap exists because the earlier security finding on this file asked for the list to be bounded, and the cost it trades for is the one described here: past 4,096 rejected files, some are probed again on a later scan. A library needs more than four thousand damaged audio files at once to reach that, and the outcome is extra probes, not wrong data. Persisting rejection fingerprints would need a schema change and belongs in its own change if a real library ever hits the cap.
There was a problem hiding this comment.
Understood. I’ll withdraw the suggestion for this PR. The bounded cache is a reasonable tradeoff: exceeding the cap can cause repeated probes, but not incorrect library data. Persisting fingerprints can be considered separately if the limit becomes a problem in practice.
Problem
Related issue: N/A
Validation tasks: none. #1254 C1 and C5 and #1256 C8 and C11 cover this behavior, but none of those cases has passed yet.
Other clients: N/A (server-side metadata fix; every client shows the corrected titles, credits, series, and chapters without changes)
The audiobook scanner read tags in ways that gave messy but common libraries wrong results. A multi-file mp3 book took its first track's title ("Chapter 01") as the book title and then never matched a provider. Parts played in filename order even when track tags said otherwise ("Chapter Four" before "Chapter One"). A multi-part m4b lost its embedded chapters. One damaged part kept the whole book out of the library, and every scan probed it again. "First Writer, Second Writer" became a single person. Series in m4b movement atoms or in a grouping tag were ignored, and positions like "Book 3" stored no number. The short description won over the long one.
This change fixes how the scanner reads one book's files. It does not change which files form a book, provider matching, or when the scanner may overwrite matched metadata.
Approach
albumtag when the parts'titletags differ or read like track titles ("Chapter 3", "Track 03", "07"). Without an album tag such a book takes its title from the folder name. A single-file book still usestitle, thenalbum.IsProbeRejectionclassifies as damaged is left out with a warning, and the book is built from its readable parts. A book with no readable part still fails. Other probe failures, such as a missing ffprobe or unreadable storage, still fail the book, so a transient problem cannot drop parts. The scan summary log reportsunreadable_files. The rejection is remembered by path, size, and mtime for the life of the process, so an unchanged rescan neither probes the part again nor rebuilds the book. A restart costs one more probe per rejected part. The list holds at most 4096 files; when full it drops an arbitrary entry, which costs one more probe of that file. If a part that was already indexed becomes unreadable, its row is marked missing and the remaining parts are renumbered. If every part of an indexed book becomes unreadable, its rows are marked missing too.;always splits.&,and, and,split only when every piece has at least two words, so "King, Stephen", "Martin Luther King, Jr.", and "Simon & Schuster" stay whole. This is close to Audiobookshelf's name parser, without its Last-First pairing. Known limit: a "Last, First" name where both halves have two words ("Le Guin, Ursula K.") splits in two, as it also does in Audiobookshelf. Names are deduplicated case-insensitively, soaudiobookPeopleCreditsEqualsees the same set on every scan. One tag yields at most 20 credits of up to 200 bytes each. Duplicate detection across folders now follows one rule: a moved or renamed folder keeps its item, and two copies on disk are two items. An existing item is reused only when every tagged author and narrator appears on it (it may carry more, as a provider-matched book does) and none of its indexed files in the library is still on disk. A stat error other than not-exist counts as present. Before, whether two copies shared an item depended on scan worker timing.©mvn/©mvimovement atoms,©nrt, or©pub. A small reader pulls them frommoov/udta/meta/ilstfor.m4b/.m4a/.mp4. It reads box headers and a few small values only, never the audio. Agroupingtag counts as a series only when it ends in a position ("Saga Add online recap and preview marker support #2", "Saga, Book 2", "Saga Vol. 3"), because grouping also holds works and store categories.parseSeriesIndexnow accepts "Book 3", "Rename webhook sync actors to profile mappings #3", "Vol. 3", "No. 3", "Part 3", and Roman numerals; ebooks share this parser.synopsis(the m4b long description,ldes) wins overdescription./or;splits only on those, as Audiobookshelf does, so "Mystery, Thriller & Suspense/Fiction" keeps the Audible category whole. A value with neither still splits on,, so a standalone "Mystery, Thriller & Suspense" still becomes two genres.Existing libraries: unchanged books are skipped by size and mtime, so these fixes reach new books and books whose files change. A part that later becomes damaged also triggers a rebuild of its book. I did not add a one-time forced rebuild. Today, reprocessing a provider-matched book resets its year and credits to the tag values, so forcing every book through the scanner would undo provider matches across the library. A rebuild can follow once the separate change that stops that overwrite lands. Overview and genres only fill empty fields or add values, so the long description reaches existing books only where the overview is empty.
Validation
go test ./internal/scanner/... ./internal/audiobooks/...pass. New table tests cover credit splitting, series positions and grouping, genre splitting, part order, the title rule, and the MP4 atom reader. One real-ffprobe test covers a book with a damaged part.make embed-stub,go build ./...,gofmt -l .,go mod tidy -diff,go vet ./...,make lint-changed(0 issues),make lint-router-recovery,make verify-local-paths,make verify-size-ratchet,make verify-bidi, andmake verify-case-collisionspass.make test-go: every package this change touches passes. On the test host,internal/api/handlers,internal/backup,internal/ebookconvert,internal/mediasample,internal/playback, andinternal/uploadsfailed under a 0002 umask (temp dirs are group-writable, which those packages refuse). Withumask 022, all of them pass except two real-FFmpeg tests (TestRunStatsWithRealFFmpeg,TestCopyRemuxSubtitleRenditionRealFFmpeg). Those run against the host's FFmpeg 6.1 in packages this change does not touch.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-4203/
Nothing visible changes in the UI layout. The data the UI shows changes; this is how I checked it.
Fixture library: synthetic tone files with real-world tag layouts written with mutagen. I ran each book through the real parse with local ffprobe, then scanned the library on an isolated sandbox built from this branch (jellyfin-ffmpeg 8.1.3) and read back the database and the Audiobookshelf-compatible API.
title="Chapter 0N",album="Real Book Title"unreadable_files=1artist="First Writer, Second Writer", narrator"Reader One; Reader Two"©mvn="Movement Saga",©mvi=4grouping="Grouping Saga #2"descandldesRescan of the unchanged library:
processed=45 failed=1 skipped=44. No rejection warning appeared, so the damaged part was not probed again. Noitem_people,media_files, oraudiobook_seriesrow was rewritten (row versions identical before and after). After I overwrote part 2 of an indexed 3-part book with random bytes, the next scan marked that part missing and renumbered the others 1–2 of 2. The scan after that skipped the book.Risks
probe_failed_at.Checklist
AI Disclosure
code-reviewskill, medium effort) reported 10 findings. Fixed: the moov/meta fallback in the MP4 reader misread QuickTime-style meta (removed), the grouping pattern lacked a word boundary, a damaged part's row was retired only under the new item, and track parsing duplicated an existing helper. The "Le Guin, Ursula K." split is kept as a documented limit. Reordering existing books by tags is the intended fix and is listed under Risks. The remaining findings were deliberate choices.🤖 Generated with Claude Code
Note
Fix audiobook scanner tag parsing: titles, part order, chapters, credits, series
parseAudiobookPartsworkflow that orders parts by disc/track tags when complete, merges MP4 book atoms (movement name/index, narrator, publisher) under ffprobe tags, and falls back to a filename chapter when a multipart file has no embedded chaptersupsertAudiobookPeople, keeping legacy single-name fields for compatibilityparseSeriesIndex, including prefixed values and Roman numerals; prefers synopsis over description for the overviewmissing_sinceviaretireUnreadableAudiobookFilesandupsertAudiobookPresentationTxaudiobookCreditsContain) and no present candidate files (pickAudiobookDuplicate); two on-disk copies index as separate itemsparseSeriesIndexin audiobook_scan.go now accepts prefixed and Roman-numeral positionsMacroscope summarized c191111.