Skip to content

feat(markers): detect episode credits from chapters and ending audio - #1541

Merged
Quick104 merged 19 commits into
mainfrom
outro/c2-episode-credits
Sep 27, 2026
Merged

Quick104 merged 19 commits into
mainfrom
outro/c2-episode-credits

Conversation

@Quick104

@Quick104 Quick104 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #730, #1147
Validation tasks: changes #1148 C1; changes #1149 C1; changes Silo-Server/silo-apple#311 C1; changes Silo-Server/silo-apple#312 C1; changes Silo-Server/silo-android#321 C1; changes Silo-Server/silo-android#322 C1

Silo stores, serves and plays credits markers, but local detection only finds intros. Credits come only from TheIntroDB or manual edits, so most episodes have no Skip Credits button and no next-episode countdown at the right moment. This change detects TV episode credits locally from authored credits chapters and from ending audio that repeats across a season.

This is part of a stacked series that adds local credits (outro) detection on a shared media sampling package. Review and merge in order; each PR targets the previous branch.

Approach

  • Chapters: the last chapter titled Credits, End Credits, End Titles, Outro, ED/ED1…, or (TV only) Ending, near the end of the file and 15–450 s long. Titles such as Opening Credits, Post-Credits Scene and "Credits End" are rejected, as are ambiguous neighbors. A following chapter's start ends the credits, so a post-credits scene stays outside them; only a last chapter snaps to the end of the file. Chapter credits are copied to other versions of the same episode from the chapter-bearing version whose duration is within 3 s.
  • Ending audio: each episode's last 450 s (or 40% if shorter) is fingerprinted once and cached as a credits_fingerprint artifact, then compared across the season with the intro matcher using credits bounds. Only matches confirmed by at least two other episodes that reach the end of the file are written.
  • Priority: each kind is owned separately, so manual, online and S3 credits are never overwritten, and an online intro no longer blocks local credits. New algorithm IDs rank below chapter results in the scanner algorithm priority. Automatic contribution to TheIntroDB stays intro-only.
  • Playback: lazy playback asks only for the kinds a file lacks and respects a settled credits season, so an episode without detectable credits doesn't rerun the season comparison on every start. With on_demand online storage, the online markers stay laid over each reload, so local analysis fills only the kinds players are missing.
  • Admin actions: the frozen v1 refresh-markers and redetect-intro routes and the v2 redetect-intro action stay intro-only; only v2 refresh-markers also runs credits. A season group with a failed marker write stays retryable.
  • The run summary gains credits counters. Task, setup-wizard and library-toggle text now say intros and credits; setting keys and API fields are unchanged.

Detected credits reach clients through the existing credits fields, marker_segments, and jellycompat /MediaSegments as Outro. No API shape changes, so no client work is required.

Validation

  • Tests for chapter titles (positive and negative), reverse scan and neighbors, tail-window offsets, the two-confirmation and end-of-file rules, source priority, version copy, lazy per-kind gaps, algorithm ranking, and contribution staying intro-only: pass.
  • End-to-end run on synthesized seasons with jellyfin-ffmpeg 7.1.4: credits fingerprints cached and credits written.
  • On a 144-episode test library, chapter and audio credits were written and the run summary matched the database. The accuracy of the combined rules is covered in the next PR.
  • make lint-changed, web Prettier/tsc/tests for the changed labels: pass.

Risks

Each episode's tail is read once more during the first analysis run. The read runs at background priority and is cached.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (in T3 Code), using its Workflow tool to run subagents
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5[1m] (main session), claude-opus-5-5 (implementation and review subagents)
  • Involvement: Fully AI-generated, not yet human verified
  • Adversarial review: A separate Claude Code review agent (claude-opus-5-5) checked the chapter and audio rules against the validated prototype, source-priority safety per kind, lazy playback gaps, contribution scope, artifact key namespacing and docs. It found one major issue: lazy playback re-ran both season comparisons on every start of an episode that had an intro but no credits. That is fixed and covered by a test.

🤖 Generated with Claude Code

Note

Detect episode end credits from chapters and tail-audio fingerprints

  • Adds credits detection alongside intro detection. Credits come from authored credits chapters (with anime ED title support), copying to compatible episode versions, and season-wide tail-window Chromaprint comparison that requires the match to reach file EOF.
  • Introduces per-kind marker handling: intro and credits markers get independent ownership, priority, confidence, and database fields. Admin refresh-markers v2 analyzes both kinds; legacy routes and redetect-intro stay intro-only.
  • Adds the internal/mediasample package for shared ffmpeg execution, capability caching, silence parsing, concurrency limiting, and Linux background process priority. Intro and silence analysis now run through it.
  • Extends artifact storage to a generalized kind/status model with failure backoff per recording node, covered by the generalize_media_analysis_artifacts migration.
  • Playback lazy markers now request only the missing marker kind and keep on-demand online intro markers across local analysis via OverlayOnline.
  • Behavioral Change: legacy refresh callers route through the kind-aware path with intro-only selection; rollback of the artifact migration deletes non-intro artifact rows; fingerprint lookups now require matching window identity, which may recompute cached fingerprints.

Macroscope summarized 28de0c5.

Quick104 and others added 6 commits September 26, 2026 22:29
…tive starts

The silencedetect parser now reads silence_start and silence_end events in
output order and pairs each end with the most recent open start, instead of
matching them by index. Values may be negative or use an exponent because
ffmpeg prints them with %.6g; a negative window-relative start is clamped to
the window start, and an end with no open start is ignored. A table test
covers these cases along with a trimmed jellyfin-ffmpeg 7.1.4 excerpt.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The intro fingerprint table now stores per-file media analysis artifacts of any kind, with a status (complete, unusable, failed), failure backoff, and the server that recorded a failure. The migration only adds columns and keeps the primary key, so binaries from before this change keep reading and upserting intro fingerprints during a rolling deploy. The repository gains generic load, upsert, and failure methods, and the intro fingerprint methods become thin wrappers over them. This gives later analysis kinds, such as credits fingerprints, a place to cache results and failures without new tables.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ing package

Intro detection built its own ffmpeg argv, parsed silencedetect output, decoded raw Chromaprint, and limited concurrency inside intromarkers. That code now lives in internal/mediasample behind a typed, JSON-serializable Request and a Runner that records runs under a new analysis process-metrics workload, so later detectors and remote nodes can share it. Capability checks are cached per ffmpeg binary identity and reset alongside the tonemap probe cache on re-probe. Fingerprint output and silence events are unchanged against jellyfin-ffmpeg 7.1.4.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local marker analysis now finds TV episode credits. It reads authored credits
chapters first, copies them to other versions of the same episode, and
otherwise compares a cached Chromaprint fingerprint of each episode's tail
across the season, writing only strong matches that reach the end of the file.
Each marker kind is owned separately, so higher-priority credits are never
overwritten and an online intro no longer blocks local credits. Playback
analysis asks only for the kinds the file lacks and keeps a settled credits
season, so an episode without detectable credits does not repeat the season
comparison on every start.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…O priority

Scheduled and admin-triggered intro/outro analysis now starts its ffmpeg child at nice 19 in the idle I/O class on Linux, so fingerprinting and silence refinement only use CPU and disk time that playback leaves free. Analysis started from playback keeps normal priority. The child is forked from a dedicated locked thread whose priority is lowered and then discarded, with a handoff when that goroutine lands on the main thread so the server itself never stays lowered. If the priority cannot be lowered, one warning is logged and the run continues; other platforms are unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… windows

The local marker analyzer now takes a marker kind and a fingerprint window instead of assuming an intro at the start of the file. A markerKind enum drives candidate ownership, effective sources, and MarkerPatch writes, and candidates carry the credits marker columns. Matching bounds, confidences, and the algorithm label move into a per-kind matchProfile, and segments are offset by the window start. Intro detection keeps the same results and stored keys, so credits detection can build on this without a behavior change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 64f45746-7213-45cd-bd55-164a25bf28bb

📥 Commits

Reviewing files that changed from the base of the PR and between 87bd9d2 and 9d5af8f.

📒 Files selected for processing (81)
  • docs/admin-catalog-api.md
  • docs/architecture/intro-detection.md
  • docs/architecture/media-sampling.md
  • docs/markers-api.md
  • docs/operations/profiling.md
  • internal/api/handlers/admin_intro.go
  • internal/api/handlers/admin_intro_test.go
  • internal/api/handlers/admin_marker_population.go
  • internal/api/handlers/playback.go
  • internal/api/handlers/playback_lazy_markers.go
  • internal/api/handlers/playback_lazy_markers_test.go
  • internal/database/media_analysis_artifacts_migration_test.go
  • internal/intromarkers/analyzer.go
  • internal/intromarkers/analyzer_credits.go
  • internal/intromarkers/analyzer_credits_test.go
  • internal/intromarkers/analyzer_parallel_test.go
  • internal/intromarkers/analyzer_test.go
  • internal/intromarkers/artifact.go
  • internal/intromarkers/artifact_db_test.go
  • internal/intromarkers/artifact_test.go
  • internal/intromarkers/chromaprint.go
  • internal/intromarkers/chromaprint_test.go
  • internal/intromarkers/compare.go
  • internal/intromarkers/compare_test.go
  • internal/intromarkers/credits.go
  • internal/intromarkers/credits_audio.go
  • internal/intromarkers/credits_chapter.go
  • internal/intromarkers/credits_chapter_test.go
  • internal/intromarkers/credits_guard.go
  • internal/intromarkers/credits_test.go
  • internal/intromarkers/kind.go
  • internal/intromarkers/kind_db_test.go
  • internal/intromarkers/kind_test.go
  • internal/intromarkers/priority_linux_test.go
  • internal/intromarkers/repository.go
  • internal/intromarkers/repository_test.go
  • internal/intromarkers/silence.go
  • internal/intromarkers/silence_backfill_db_test.go
  • internal/intromarkers/silence_test.go
  • internal/intromarkers/slot_limiter.go
  • internal/intromarkers/types.go
  • internal/intromarkers/types_test.go
  • internal/intromarkers/window.go
  • internal/intromarkers/window_test.go
  • internal/markers/contribute_test.go
  • internal/markers/overlay.go
  • internal/markers/overlay_test.go
  • internal/markers/population.go
  • internal/markers/write.go
  • internal/markers/write_test.go
  • internal/mediasample/args.go
  • internal/mediasample/args_test.go
  • internal/mediasample/caps.go
  • internal/mediasample/caps_test.go
  • internal/mediasample/chromaprint.go
  • internal/mediasample/chromaprint_test.go
  • internal/mediasample/doc.go
  • internal/mediasample/ffmpeg_test.go
  • internal/mediasample/limiter.go
  • internal/mediasample/limiter_test.go
  • internal/mediasample/priority_linux.go
  • internal/mediasample/priority_linux_test.go
  • internal/mediasample/priority_other.go
  • internal/mediasample/priority_other_test.go
  • internal/mediasample/request.go
  • internal/mediasample/request_test.go
  • internal/mediasample/run.go
  • internal/mediasample/run_test.go
  • internal/mediasample/silence.go
  • internal/mediasample/silence_test.go
  • internal/mediasample/stderr.go
  • internal/processmetrics/completed.go
  • internal/proxy/reprobe.go
  • internal/taskmanager/tasks/detect_intro_markers.go
  • internal/tonemap/preflight.go
  • internal/tonemap/probe.go
  • internal/transcodenode/reprobe.go
  • migrations/sql/20260926190719_generalize_media_analysis_artifacts.sql
  • web/src/components/admin/libraries/LibraryFormSections.tsx
  • web/src/pages/admin-settings/MarkerTasksCard.tsx
  • web/src/pages/setup-wizard/steps/FeaturesStep.tsx
 _________________________
< Think twice, code once. >
 -------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-09-27T18:51:11.248574Z 28de0c5 New commits
ℹ️ 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.

@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: cea24ffcd9

ℹ️ 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 thread internal/intromarkers/analyzer.go Resolved

@Quick104 Quick104 left a comment

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.

AI review: OpenAI Codex (gpt-6-astra), using GitHub CLI.

Quick104 and others added 10 commits September 27, 2026 11:55
…ilure

RecordArtifactFailure locked the artifact row before deciding whether a
failure may replace it, but that lock covers nothing when the row does not
exist yet. Another server's first complete result, inserted in that gap, was
then overwritten by the failure upsert. Without a row, the failure is now
inserted only if the key is still free; if a row appeared meanwhile, it is
locked and judged again, so a settled result for the same file stands.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…a timer

assertWaiting treated a 20 ms timeout as proof that Acquire was blocked,
so a goroutine the scheduler had not yet run could pass as waiting. The
asynchronous limiter tests now run in a synctest bubble and call
synctest.Wait, which returns only once the Acquire goroutine is durably
blocked or done. acquireAsync closes its channel when Acquire fails, so
an error is not mistaken for waiting.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…e missing kind

With markers.online_storage set to on_demand, playback's marker updates reloaded the stored row before and after local analysis, so players lost the online intro or credits they had just been shown, and local analysis was asked for a kind the player already had. The playback handler now keeps the on-demand lookup and lays its online and plugin markers back over each reload with the new markers.OverlayOnline, which uses the same precedence as ApplyResult: manual markers still win, and a fresh lookup replaces an online marker left over from stored mode. Missing kinds are worked out from the file players see, so an online intro sends local analysis after credits only. Stored mode is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ing version

A credits chapter followed by its own chapter, such as a post-credits scene, now ends where that chapter starts even within 15 seconds of the end of the file; only the last chapter's end snaps to the end. Before, Skip Credits jumped over the authored scene. A version of an episode without chapters now copies chapter credits from the chapter-bearing version whose duration it matches, not from whichever was listed first, which rejected valid copies when an episode had several chapter-bearing versions.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
When a credits marker failed to write, the season group was still recorded as complete, so scheduled and playback analysis skipped it until its inputs changed and the missing marker was never retried. The group is now recorded as failed, which is not settled, so the next run analyzes it again. settleSeasonState keeps a failed status instead of turning it into partial, which would settle the group for a week.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Admin refresh started analyzing credits as well as intros for every caller, which changed the frozen /api/v1 refresh-markers and redetect-intro routes and the v2 redetect-intro port of them. Those now analyze episode intros only, as before credits existed. Only v2 refresh-markers, in local and both modes, runs intro and credits analysis. The analyzer gains AnalyzeEpisodeKinds so the handler chooses the kinds.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@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: 1cd1be2ac7

ℹ️ 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 thread internal/markers/overlay.go Resolved
Quick104 and others added 2 commits September 27, 2026 12:24
…m playback reloads

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…k and lookups

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@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: 9d5af8f0ae

ℹ️ 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".

Base automatically changed from outro/c1-analyzer-kinds to main September 27, 2026 18:49
# Conflicts:
#	docs/architecture/intro-detection.md
#	internal/intromarkers/analyzer.go
#	internal/intromarkers/analyzer_test.go
#	internal/intromarkers/compare.go
#	internal/intromarkers/repository.go
#	internal/intromarkers/types.go
@kody-ai

kody-ai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the `@kody start-review` command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Providing Context (Files & MCPs)

Add these hints in your PR description (or a comment) to unlock deeper checks:

  • Ticket / Acceptance Criteria: `Refs: ABC-123` (Linear/Jira/Asana/ClickUp/Trello) or a direct ticket link.
  • Bugfix Validation: a Sentry/Datadog/Bugsnag event link (or paste the stack trace/error message).
  • Endpoint Risk: mention the route (e.g., `POST /api/payments`) or controller/action name.
  • Attach a repo file as context: use an explicit marker like `@file:docs/guide.mdx#L10-L50` (replace with your real path).
  • API Contract Docs: include `@file:openapi.yaml` or `@file:swagger.json` when changing routes/schemas.
  • Definition of Done / Standards: include `@file:DOD.md` or `@file:CONTRIBUTING.md` if your repo has them.
  • Design System Source of Truth: include `@file:ui/index.ts` (replace with your DS entrypoint path).
  • Feature Flags: include the flag key/name and `@file:flags.ts` / `@file:config.json` (and optionally the PostHog flag name).
  • Edge/CDN Rules: link the Cloudflare rule/zone or describe the intended redirect/header behavior.
  • Attach an MCP tool output: use `@mcp<provider|tool>` (replace with an installed MCP provider + tool, e.g., `@mcp<sentry|events.search>`).
Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Access your configuration settings here.

@Quick104
Quick104 merged commit 10284e8 into main Sep 27, 2026
9 of 16 checks passed
@Quick104
Quick104 deleted the outro/c2-episode-credits branch September 27, 2026 18:51
state.Status = seasonStatusFailed
state.LastError = err.Error()
if opts.persistState {
_ = a.repo.UpsertSeasonState(ctx, state, analysisHash)

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 medium

The _ = silently discards the error returned by UpsertSeasonState, violating rule 5, which requires explicit handling of errors from SDK/gRPC-backed calls. This swallows any persistence failure in the summary and logs; record the error (e.g., append it to summary.Errors) instead of dropping it.

Kody rule violation: Avoid ignoring errors from SDK/gRPC calls

if err := a.repo.UpsertSeasonState(ctx, state, analysisHash); err != nil {
	summary.Errors = append(summary.Errors, err.Error())
}

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

@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: 28de0c5fb5

ℹ️ 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 +121 to +123
if !opts.force && existing != nil && existing.InputSignature == state.InputSignature && existing.settled(time.Now()) {
summary.CreditsGroupsSkipped++
return summary, nil

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 Let credits artifacts retry before skipping the group

When a credits fingerprint extraction fails, settleSeasonState persists the shared season row as partial, and SeasonState.settled treats that state as settled for seven days. This guard therefore skips the group before checking the failed artifact's 12-hour RetryAfter; the next daily task cannot retry it, and another replica cannot perform the intended immediate retry for a node-local failure. A transient tail decode failure can consequently delay the entire credits group for a week, so the skip interval should respect artifact retry eligibility.

AGENTS.md reference: AGENTS.md:L13-L18

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant