The audiobook scanner needs format-level tags (title, artist, album, date) for media_items metadata; ffprobe already parses them in ffprobeFormat.Tags but ProbeData previously discarded them. Add FormatTags map[string]string to ProbeData, populate it in convertProbeData via a new normalizeFormatTags helper that lowercases keys and trims values. Adds a fixture audiobook .m4b with embedded chapters (Intro/Outro) and format tags, and a test that verifies ProbeFile() returns both correctly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package scanner
|
|
|
|
import (
|
|
"context"
|
|
"os/exec"
|
|
"testing"
|
|
)
|
|
|
|
func TestProbeFileAudiobookFixture(t *testing.T) {
|
|
if _, err := exec.LookPath("ffmpeg"); err != nil {
|
|
t.Skip("ffmpeg not available; skipping fixture-based test")
|
|
}
|
|
|
|
ffprobePath := FFprobePathFromFFmpeg("ffmpeg")
|
|
if _, err := exec.LookPath(ffprobePath); err != nil {
|
|
// Fall back to plain "ffprobe" on PATH
|
|
ffprobePath = "ffprobe"
|
|
if _, err := exec.LookPath(ffprobePath); err != nil {
|
|
t.Skip("ffprobe not available; skipping fixture-based test")
|
|
}
|
|
}
|
|
|
|
ctx := context.Background()
|
|
got, err := ProbeFile(ctx, ffprobePath, "testdata/audiobook_fixtures/single_book/book.m4b")
|
|
if err != nil {
|
|
t.Fatalf("ProbeFile: %v", err)
|
|
}
|
|
|
|
// Chapters
|
|
if len(got.Chapters) != 2 {
|
|
t.Errorf("Chapters = %d, want 2", len(got.Chapters))
|
|
} else {
|
|
if got.Chapters[0].Title != "Intro" {
|
|
t.Errorf("Chapters[0].Title = %q, want %q", got.Chapters[0].Title, "Intro")
|
|
}
|
|
if got.Chapters[1].Title != "Outro" {
|
|
t.Errorf("Chapters[1].Title = %q, want %q", got.Chapters[1].Title, "Outro")
|
|
}
|
|
}
|
|
|
|
// Format tags
|
|
if got.FormatTags == nil {
|
|
t.Fatal("FormatTags is nil")
|
|
}
|
|
if title := got.FormatTags["title"]; title != "Test Audiobook" {
|
|
t.Errorf("FormatTags[\"title\"] = %q, want %q", title, "Test Audiobook")
|
|
}
|
|
if artist := got.FormatTags["artist"]; artist != "Test Author" {
|
|
t.Errorf("FormatTags[\"artist\"] = %q, want %q", artist, "Test Author")
|
|
}
|
|
if album := got.FormatTags["album"]; album != "Test Series" {
|
|
t.Errorf("FormatTags[\"album\"] = %q, want %q", album, "Test Series")
|
|
}
|
|
}
|