* docs(markers): design + implementation plans for multi-source markers & TheIntroDB contribution * fix(markers): TheIntroDB read-path correctness (TVDB, real confidence, best candidate) Honor TVDB ids in /media lookups (previously dropped — anime/TheTVDB-first libraries got no markers), decode and use the real per-segment confidence and submission_count instead of a hardcoded 0.9, and pick the most-submitted / highest-confidence candidate when several are returned. Adds httptest coverage for the introdb client and provider. Phase 1 of docs/superpowers/plans/2026-06-06-marker-sources-and-contribution-implementation.md Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(markers): multi-source dispatch, per-provider config, per-segment provenance Add marker_provider_config (per-provider fetch enable/priority + contribute gates, contribution off by default) and a cached ProviderConfigStore. Add Registry.FetchMerged: query all fetch-enabled providers concurrently and keep the best candidate per segment (submission_count, then confidence, then fetch priority), stamping each winning marker with its provider/algorithm. Thread per-segment provenance through MarkerUpdatePayload and scanner.MarkerUpdate (additive SegmentProvenance overrides) so a merged result writes correct per-segment provider/confidence/algorithm; the legacy shared columns keep a summary. The lazy-playback path now uses FetchMerged. With only TheIntroDB enabled, behavior is unchanged. Phase 2 of docs/superpowers/plans/2026-06-06-marker-sources-and-contribution-implementation.md Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(markers): TheIntroDB submission client, contribution audit, service engine Add a markers.Submitter capability and implement it on the introdb provider (POST /v3/submit, GET /v3/user/stats; key required, usage-limit aware, applies the null start/end conventions). Add the marker_contributions audit table and a value-hash-keyed ContributionStore for idempotency. Add ContributionService: resolves enabled submitter providers, gates eligibility (never re-submit online-sourced markers; auto runs require contribute_auto_local + scanner-intro above the per-provider confidence threshold), checks idempotency, submits, and records. Wired in main.go; no trigger yet (admin API and task follow). Phase 3 of docs/superpowers/plans/2026-06-06-marker-sources-and-contribution-implementation.md Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(api): admin marker editing, contribution, and provider config endpoints Add the RequireAdmin marker API: GET/PUT /admin/files/{id}/markers (read with provenance; manual upsert where a segment object sets and null clears), DELETE .../markers/{segment}, POST .../contribute and GET .../contributions, plus GET/PUT /admin/markers/providers[/{provider}] and a .../validate key-check returning user stats. Manual writes go through the priority-gated UpsertMarkers (source=manual) and notify live sessions; a new FileRepository.ClearMarkers nulls a segment's columns. Validation mirrors the contribution rules. Phase 4 of docs/superpowers/plans/2026-06-06-marker-sources-and-contribution-implementation.md Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(markers): daily auto-contribution task for local intro markers Add ContributeMarkersTask (daily 04:00, after local detection): when a provider has contribute_enabled + contribute_auto_local, page through episode files with a scanner intro marker at/above the provider's confidence threshold (new ContributionStore.CandidateLocalIntroFiles keyset query) and run them through ContributionService with Auto=true. No-op when no provider opts in; idempotent and resumable across runs. Phase 5 of docs/superpowers/plans/2026-06-06-marker-sources-and-contribution-implementation.md Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(intromarkers): refine chromaprint starts with dialogue cues * feat(markers): finish marker management backend * feat(web): add marker editing UI * feat(markers): use plugin marker providers * fix(markers): address PR review feedback * feat(player): show marker labels on seek hover * fix(markers): type nullable marker mutation params * feat(markers): audit marker edits and add permission --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
169 lines
4.1 KiB
Go
169 lines
4.1 KiB
Go
package intromarkers
|
|
|
|
import (
|
|
"context"
|
|
"math"
|
|
"testing"
|
|
|
|
"github.com/Silo-Server/silo-server/internal/models"
|
|
)
|
|
|
|
func TestDialogueBoundaryRefinerMovesStartPastEarlyDialogue(t *testing.T) {
|
|
cfg := DefaultConfig("ffmpeg")
|
|
segment := Segment{
|
|
Start: 322.014,
|
|
End: 363.465,
|
|
Confidence: 0.85,
|
|
Algorithm: ChromaprintAlgorithm,
|
|
}
|
|
candidate := Candidate{
|
|
FileID: 636600,
|
|
AudioLanguage: "eng",
|
|
ExternalSubtitles: []models.ExternalSubtitle{
|
|
{Path: "/episode.en.srt", Language: "en", Format: "srt"},
|
|
},
|
|
}
|
|
refiner := &DialogueBoundaryRefiner{
|
|
config: cfg,
|
|
readFile: func(path string) ([]byte, error) {
|
|
return []byte(swatS05E02IntroLeadInSRT), nil
|
|
},
|
|
}
|
|
|
|
refined, ok, err := refiner.RefineChromaprintStart(context.Background(), candidate, segment)
|
|
if err != nil {
|
|
t.Fatalf("RefineChromaprintStart returned error: %v", err)
|
|
}
|
|
if !ok {
|
|
t.Fatal("expected dialogue refinement to apply")
|
|
}
|
|
if math.Abs(refined.Start-330.852) > 0.001 {
|
|
t.Fatalf("refined start = %.3f, want 330.852", refined.Start)
|
|
}
|
|
if refined.End != segment.End {
|
|
t.Fatalf("refined end = %.3f, want %.3f", refined.End, segment.End)
|
|
}
|
|
if refined.Algorithm != ChromaprintDialogueAlgorithm {
|
|
t.Fatalf("algorithm = %q, want %q", refined.Algorithm, ChromaprintDialogueAlgorithm)
|
|
}
|
|
}
|
|
|
|
func TestDialogueBoundaryRefinerIgnoresMusicCues(t *testing.T) {
|
|
cfg := DefaultConfig("ffmpeg")
|
|
segment := Segment{Start: 100, End: 150, Confidence: 0.85, Algorithm: ChromaprintAlgorithm}
|
|
candidate := Candidate{
|
|
FileID: 1,
|
|
AudioLanguage: "en",
|
|
ExternalSubtitles: []models.ExternalSubtitle{
|
|
{Path: "/episode.en.srt", Language: "en", Format: "srt"},
|
|
},
|
|
}
|
|
refiner := &DialogueBoundaryRefiner{
|
|
config: cfg,
|
|
readFile: func(path string) ([]byte, error) {
|
|
return []byte("1\n00:01:40,000 --> 00:01:48,000\n♪ Opening theme ♪\n\n"), nil
|
|
},
|
|
}
|
|
|
|
refined, ok, err := refiner.RefineChromaprintStart(context.Background(), candidate, segment)
|
|
if err != nil {
|
|
t.Fatalf("RefineChromaprintStart returned error: %v", err)
|
|
}
|
|
if ok {
|
|
t.Fatalf("music cue should not refine segment, got %+v", refined)
|
|
}
|
|
}
|
|
|
|
func TestDialogueBoundaryRefinerKeepsMinimumRemainingDuration(t *testing.T) {
|
|
cfg := DefaultConfig("ffmpeg")
|
|
segment := Segment{Start: 100, End: 112, Confidence: 0.85, Algorithm: ChromaprintAlgorithm}
|
|
candidate := Candidate{
|
|
FileID: 1,
|
|
AudioLanguage: "en",
|
|
ExternalSubtitles: []models.ExternalSubtitle{
|
|
{Path: "/episode.en.srt", Language: "en", Format: "srt"},
|
|
},
|
|
}
|
|
refiner := &DialogueBoundaryRefiner{
|
|
config: cfg,
|
|
readFile: func(path string) ([]byte, error) {
|
|
return []byte("1\n00:01:40,000 --> 00:01:45,000\nStill talking.\n\n"), nil
|
|
},
|
|
}
|
|
|
|
refined, ok, err := refiner.RefineChromaprintStart(context.Background(), candidate, segment)
|
|
if err != nil {
|
|
t.Fatalf("RefineChromaprintStart returned error: %v", err)
|
|
}
|
|
if ok {
|
|
t.Fatalf("refinement should not leave too-short intro, got %+v", refined)
|
|
}
|
|
}
|
|
|
|
func TestSelectDialogueSubtitlePrefersAudioLanguage(t *testing.T) {
|
|
candidate := Candidate{
|
|
AudioLanguage: "eng",
|
|
ExternalSubtitles: []models.ExternalSubtitle{
|
|
{Path: "/episode.es.srt", Language: "es", Format: "srt"},
|
|
{Path: "/episode.en.srt", Language: "en", Format: "srt"},
|
|
},
|
|
}
|
|
|
|
subtitle, ok := selectDialogueSubtitle(candidate)
|
|
if !ok {
|
|
t.Fatal("expected subtitle selection")
|
|
}
|
|
if subtitle.Path != "/episode.en.srt" {
|
|
t.Fatalf("selected %q, want English sidecar", subtitle.Path)
|
|
}
|
|
}
|
|
|
|
const swatS05E02IntroLeadInSRT = `142
|
|
00:05:11,006 --> 00:05:13,051
|
|
Okay.
|
|
|
|
143
|
|
00:05:13,095 --> 00:05:15,358
|
|
I'm in.
|
|
|
|
144
|
|
00:05:15,402 --> 00:05:19,144
|
|
Never be in a hurry to die.
|
|
|
|
145
|
|
00:05:19,188 --> 00:05:20,972
|
|
Weapons are nice,
|
|
but we need intel.
|
|
|
|
146
|
|
00:05:21,016 --> 00:05:22,539
|
|
We don't know where Delfina is
|
|
|
|
147
|
|
00:05:22,583 --> 00:05:24,106
|
|
or how many people
|
|
are holding her.
|
|
|
|
148
|
|
00:05:24,149 --> 00:05:25,499
|
|
It won't be easy.
|
|
|
|
149
|
|
00:05:25,542 --> 00:05:27,196
|
|
Senor Novak has
|
|
friends everywhere.
|
|
|
|
150
|
|
00:05:27,239 --> 00:05:28,806
|
|
I got an idea
|
|
of where we can start.
|
|
|
|
151
|
|
00:05:28,850 --> 00:05:30,852
|
|
Follow me.
|
|
|
|
152
|
|
00:06:20,771 --> 00:06:22,643
|
|
Oh, keep screaming, chica.
|
|
`
|