diff --git a/internal/app/app.go b/internal/app/app.go index b8358f9..65018b3 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -1352,6 +1352,7 @@ func buildTagMetadata(trackMeta map[string]any, title, source, trackID string, o Album: album, Artist: artist, AlbumArtist: albumArtist, + OmitDiscTags: opts.forPlaylist, TrackNumber: trackNumber, DiscNumber: discNumber, TrackTotal: trackTotal, diff --git a/internal/app/app_test.go b/internal/app/app_test.go index 95c3681..a0ba5ca 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -525,6 +525,9 @@ func TestBuildTagMetadataPlaylistOmitsDiscTags(t *testing.T) { if tags.DiscTotal != 0 { t.Fatalf("disc total = %d, want 0", tags.DiscTotal) } + if !tags.OmitDiscTags { + t.Fatalf("omit disc tags = %v, want true", tags.OmitDiscTags) + } } func TestTrackOutputPathFallsBackToDisc1(t *testing.T) { diff --git a/internal/audio/tag/tagger.go b/internal/audio/tag/tagger.go index 7c231fb..2806664 100644 --- a/internal/audio/tag/tagger.go +++ b/internal/audio/tag/tagger.go @@ -14,6 +14,7 @@ type Metadata struct { Album string Artist string AlbumArtist string + OmitDiscTags bool TrackNumber int DiscNumber int TrackTotal int @@ -101,6 +102,14 @@ func buildFFmpegArgs(inputPath, outputPath string, meta Metadata, coverPath, ext } args = append(args, "-metadata", k+"="+v) } + if meta.OmitDiscTags { + args = append(args, + "-metadata", "disc=", + "-metadata", "disk=", + "-metadata", "disctotal=", + "-metadata", "totaldiscs=", + ) + } args = append(args, outputPath) return args diff --git a/internal/audio/tag/tagger_test.go b/internal/audio/tag/tagger_test.go index 9c3d0d8..be3803d 100644 --- a/internal/audio/tag/tagger_test.go +++ b/internal/audio/tag/tagger_test.go @@ -96,6 +96,28 @@ func TestBuildFFmpegArgsSkipsCoverForUnsupportedContainer(t *testing.T) { } } +func TestBuildFFmpegArgsClearsDiscTagsWhenRequested(t *testing.T) { + args := buildFFmpegArgs("in.flac", "out.flac", Metadata{Title: "x", OmitDiscTags: true}, "", "flac") + want := map[string]bool{ + "disc=": false, + "disk=": false, + "disctotal=": false, + "totaldiscs=": false, + } + for i := 0; i < len(args)-1; i++ { + if args[i] == "-metadata" { + if _, ok := want[args[i+1]]; ok { + want[args[i+1]] = true + } + } + } + for tag, found := range want { + if !found { + t.Fatalf("missing clear tag %q in args: %v", tag, args) + } + } +} + func TestTaggedTempPathPreservesExtension(t *testing.T) { if got := taggedTempPath("/tmp/song.flac"); got != "/tmp/song.tmp.flac" { t.Fatalf("taggedTempPath(flac)=%q", got)