Skip to content

fix(scanner): read audiobook titles, part order, chapters, credits, and series correctly from tags - #4203

Merged
Quick104 merged 6 commits into
mainfrom
fix/audiobook-scan-tags-and-parts
Nov 15, 2026
Merged

Quick104 merged 6 commits into
mainfrom
fix/audiobook-scan-tags-and-parts

Conversation

@Quick104

@Quick104 Quick104 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Title: a multi-file book uses the album tag when the parts' title tags 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 uses title, then album.
  • Part order: parts follow disc then track tags when every part has a track number, either all or none have a disc number, and no two parts share one. Otherwise they keep natural filename order. Book tags come from the first part in the final order.
  • Chapters: a part keeps its embedded chapters. A part without them still gets one chapter named after its file. The web player and the Audiobookshelf-compatible API already lay out per-file chapters by cumulative part duration, and playback's probe repair already keeps embedded chapters on reprobe, so neither needed changes.
  • Damaged parts: a part that IsProbeRejection classifies 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 reports unreadable_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.
  • Credits: author and narrator tags split into one credit per person. ; 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, so audiobookPeopleCreditsEqual sees 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.
  • Series: ffprobe in the shipped image (jellyfin-ffmpeg 8.1.3, checked) does not expose the m4b ©mvn/©mvi movement atoms, ©nrt, or ©pub. A small reader pulls them from moov/udta/meta/ilst for .m4b/.m4a/.mp4. It reads box headers and a few small values only, never the audio. A grouping tag 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. parseSeriesIndex now accepts "Book 3", "Rename webhook sync actors to profile mappings #3", "Vol. 3", "No. 3", "Part 3", and Roman numerals; ebooks share this parser.
  • Description: synopsis (the m4b long description, ldes) wins over description.
  • Genres: a value containing / 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

  • Focused tests: 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.
  • Gate: 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, and make verify-case-collisions pass.
  • make test-go: every package this change touches passes. On the test host, internal/api/handlers, internal/backup, internal/ebookconvert, internal/mediasample, internal/playback, and internal/uploads failed under a 0002 umask (temp dirs are group-writable, which those packages refuse). With umask 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.
  • Web and generated-contract checks were not run. This change touches no web, API, or generated files.

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.

Book (fixture) Before After
5 mp3 parts, title="Chapter 0N", album="Real Book Title" title "Chapter 01" title "Real Book Title"
"Chapter One…Four.mp3", track tags 1–4 Four, One, Three, Two One, Two, Three, Four
2-part m4b, 3 embedded chapters each 2 chapters (one per file) 6 chapters; ABS timeline 0–10, 10–20, 20–30, 30–40, 40–50, 50–60 s
3 mp3 parts, part 2 random bytes book never listed, failed every scan listed with 2 parts; summary unreadable_files=1
Single zero-byte mp3 failed still fails (no readable part)
artist="First Writer, Second Writer", narrator "Reader One; Reader Two" 1 author, 1 narrator 2 authors, 2 narrators; "First Writer" is the same person row as on another book
Series positions "Book 3", "#3", "III", "3 of 8", "1.5" only "3 of 8" and "1.5" indexed 3, 3, 3, 3, 1.5
m4b with only ©mvn="Movement Saga", ©mvi=4 no series Movement Saga #4
mp3 with grouping="Grouping Saga #2" no series Grouping Saga #2
m4b with desc and ldes short description long description
genre "Mystery, Thriller & Suspense/Fiction" 3 genres 2 genres

Rescan of the unchanged library: processed=45 failed=1 skipped=44. No rejection warning appeared, so the damaged part was not probed again. No item_people, media_files, or audiobook_series row 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

  • A book whose track tags disagree with a correct filename order now follows the tags once its files change. A saved position inside such a book can then point to a different part. Conflicting or incomplete tags fall back to filename order.
  • The damaged-part memory is per process. Fixing ffprobe without changing the file takes a restart to retry that part, which matches how the movie scanner treats probe_failed_at.
  • The user manual's audiobook page still describes the old rules (filename order, metadata from the first file, the series tag list) and needs an update.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code, GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated (human verification pending)
  • Adversarial review: An independent Claude Code review of the diff (the repository code-review skill, 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

  • Replaces separate single-file and multi-file parsing with a shared parseAudiobookParts workflow 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 chapters
  • Splits multi-person author/narrator tags into full credit lists (semicolon, conjunction, ampersand, comma) and writes all credits via upsertAudiobookPeople, keeping legacy single-name fields for compatibility
  • Adds series name/position parsing from grouping tags and parseSeriesIndex, including prefixed values and Roman numerals; prefers synopsis over description for the overview
  • ffprobe-rejected parts are cached (path, size, mtime, capped) and skipped; rows for unreadable parts get missing_since via retireUnreadableAudiobookFiles and upsertAudiobookPresentationTx
  • Duplicate selection now requires candidate credit supersets (audiobookCreditsContain) and no present candidate files (pickAudiobookDuplicate); two on-disk copies index as separate items
  • Risk: genre splitting changes in audiobook_tags.go — values containing slash or semicolon no longer split on commas; parseSeriesIndex in audiobook_scan.go now accepts prefixed and Roman-numeral positions

Macroscope summarized c191111.

@silo-triage silo-triage Bot added the size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority. label Nov 14, 2026
@silo-kody

silo-kody Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4ede4d79-7481-4ac1-a05d-f38c2e3467f1
Commits

Reviewing files that changed from the base of the PR and between feae205 and c191111.

Files selected for processing: 8

  • internal/scanner/audiobook.go
  • internal/scanner/audiobook_mp4tags.go
  • internal/scanner/audiobook_scan.go
  • internal/scanner/audiobook_tags.go
  • internal/scanner/audiobook_test.go
  • internal/scanner/book_skip_postgres_test.go
  • internal/scanner/dead_root_test.go
  • scripts/ci/db-contracts.txt
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T00:23:45.888481Z c191111 New commits
🔒 Security Review ✅ Completed 2026-11-15T00:28:56.817597Z c191111 New commits

Security findings

Advisory findings (2)

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish labels Nov 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +297 to +298
if len(b.Narrators) > 0 {
b.Narrator = b.Narrators[0]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug high

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/scanner/audiobook.go Outdated
Comment on lines +259 to +265
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"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug high

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/scanner/audiobook.go Outdated
Comment on lines +229 to +230
if len(parts) == 0 {
return nil, fmt.Errorf("audiobook folder %s: ffprobe rejected every audio file (%s)", folderPath, strings.Join(book.UnreadableParts, ", "))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug high

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/scanner/audiobook.go Outdated
book.Files = make([]parsedAudiobookFile, len(parts))
for i, p := range parts {
file := p.file
if len(parts) > 1 && len(file.Chapters) == 0 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. Counting the original audio files addresses the reported case: the one readable part retains its filename-based chapter.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ 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.

Comment on lines +22 to +24
for _, group := range strings.Split(raw, ";") {
for _, joined := range splitCreditPieces(group, audiobookCreditConjunctionRE) {
for _, name := range splitCreditPieces(joined, audiobookCreditCommaRE) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Quick104 and others added 2 commits November 14, 2026 18:13
…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]>
@Quick104
Quick104 force-pushed the fix/audiobook-scan-tags-and-parts branch from 9641d02 to fcf7257 Compare November 14, 2026 23:13
@silo-kody

silo-kody Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Comment on lines +260 to +268
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"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug medium

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Kody Rules high

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/scanner/audiobook_scan.go Outdated
// editions, so the whole credit set must agree.
desired := book.credits()
for _, candidateID := range candidates {
people, err := s.itemRepo.GetPeople(ctx, candidateID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Kody Rules high

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bd3f5bc. The candidates' author and narrator credits now load in one query (content_id = ANY), and the comparison runs over that map.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. Loading candidate credits in one query addresses the per-candidate database lookup concern. I haven’t independently verified commit bd3f5bc926.

Comment thread internal/scanner/audiobook_scan.go Outdated
Comment on lines +1183 to +1184
for _, candidateID := range candidates {
people, err := s.itemRepo.GetPeople(ctx, candidateID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Performance medium

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bd3f5bc with the same change: one query for all candidates instead of one GetPeople call per candidate.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

silo-kody Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

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

silo-kody Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Comment thread internal/scanner/audiobook_scan.go Outdated
}
desired := book.credits()
for _, candidateID := range candidates {
if audiobookCreditsContain(credits[candidateID], desired) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug critical

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/scanner/audiobook_scan.go Outdated
}
desired := book.credits()
for _, candidateID := range candidates {
if audiobookCreditsContain(credits[candidateID], desired) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Bug critical

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

silo-kody Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ 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.

Comment thread internal/scanner/audiobook_tags.go Outdated
func rememberRejectedAudiobookPart(path string, size int64, modTime time.Time) {
rejectedAudiobookParts.Lock()
defer rejectedAudiobookParts.Unlock()
rejectedAudiobookParts.byPath[path] = rejectedAudiobookPart{size: size, modTime: modTime}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

silo-kody Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Comment on lines +264 to +267
if _, known := byPath[path]; !known && len(byPath) >= maxRejectedAudiobookParts {
for old := range byPath {
delete(byPath, old)
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Performance medium

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.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Quick104
Quick104 merged commit 1a4556e into main Nov 15, 2026
25 checks passed
@Quick104
Quick104 deleted the fix/audiobook-scan-tags-and-parts branch November 15, 2026 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: playback Can't play, stalls, or wrong media priority: P2 Limited scope, workaround exists, or polish size/XXL 1000–2999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant