Skip to content

Commit 0b89f40

Browse files
authored
fix(musicbrainz): filter Blu-ray media in FlatTracks (#174)
The FlatTracks function was only filtering DVD media formats, which caused issues with releases containing Blu-ray discs. When processing such releases, the Blu-ray tracks would be included alongside the audio CD tracks, resulting in a track count mismatch that prevented successful tagging.
1 parent 492a5a6 commit 0b89f40

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

musicbrainz/musicbrainz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ func IsCompilation(rg ReleaseGroup) bool {
461461
func FlatTracks(media []Media) []Track {
462462
var tracks []Track
463463
for _, media := range media {
464-
if strings.Contains(media.Format, "DVD") {
464+
if strings.Contains(media.Format, "DVD") || strings.Contains(media.Format, "Blu-ray") {
465465
// not supported for now
466466
continue
467467
}

musicbrainz/musicbrainz_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,88 @@ func TestMergeAndSortGenres(t *testing.T) {
3838
}),
3939
)
4040
}
41+
42+
func TestFlatTracks(t *testing.T) {
43+
t.Parallel()
44+
45+
t.Run("filters DVD media", func(t *testing.T) {
46+
t.Parallel()
47+
media := []Media{
48+
{Format: "DVD", Tracks: []Track{{ID: "dvd-track"}}},
49+
{Format: "CD", Tracks: []Track{{ID: "cd-track"}}},
50+
}
51+
tracks := FlatTracks(media)
52+
assert.Len(t, tracks, 1)
53+
assert.Equal(t, "cd-track", tracks[0].ID)
54+
})
55+
56+
t.Run("filters Blu-ray media", func(t *testing.T) {
57+
t.Parallel()
58+
media := []Media{
59+
{Format: "Blu-ray", Tracks: []Track{{ID: "bluray-track"}}},
60+
{Format: "CD", Tracks: []Track{{ID: "cd-track"}}},
61+
}
62+
tracks := FlatTracks(media)
63+
assert.Len(t, tracks, 1)
64+
assert.Equal(t, "cd-track", tracks[0].ID)
65+
})
66+
67+
t.Run("includes CD media", func(t *testing.T) {
68+
t.Parallel()
69+
media := []Media{
70+
{Format: "CD", Tracks: []Track{{ID: "cd-track-1"}}},
71+
{Format: "CD", Tracks: []Track{{ID: "cd-track-2"}}},
72+
}
73+
tracks := FlatTracks(media)
74+
assert.Len(t, tracks, 2)
75+
assert.Equal(t, "cd-track-1", tracks[0].ID)
76+
assert.Equal(t, "cd-track-2", tracks[1].ID)
77+
})
78+
79+
t.Run("filters video tracks", func(t *testing.T) {
80+
t.Parallel()
81+
media := []Media{
82+
{Format: "CD", Tracks: []Track{
83+
{ID: "audio-track", Recording: struct {
84+
FirstReleaseDate string `json:"first-release-date"`
85+
Genres []Genre `json:"genres"`
86+
Video bool `json:"video"`
87+
Disambiguation string `json:"disambiguation"`
88+
ID string `json:"id"`
89+
Length int `json:"length"`
90+
Title string `json:"title"`
91+
Artists []ArtistCredit `json:"artist-credit"`
92+
Relations []Relation `json:"relations"`
93+
ISRCs []string `json:"isrcs"`
94+
}{Video: false}},
95+
{ID: "video-track", Recording: struct {
96+
FirstReleaseDate string `json:"first-release-date"`
97+
Genres []Genre `json:"genres"`
98+
Video bool `json:"video"`
99+
Disambiguation string `json:"disambiguation"`
100+
ID string `json:"id"`
101+
Length int `json:"length"`
102+
Title string `json:"title"`
103+
Artists []ArtistCredit `json:"artist-credit"`
104+
Relations []Relation `json:"relations"`
105+
ISRCs []string `json:"isrcs"`
106+
}{Video: true}},
107+
}},
108+
}
109+
tracks := FlatTracks(media)
110+
assert.Len(t, tracks, 1)
111+
assert.Equal(t, "audio-track", tracks[0].ID)
112+
})
113+
114+
t.Run("includes pregap track", func(t *testing.T) {
115+
t.Parallel()
116+
pregapTrack := Track{ID: "pregap-track"}
117+
media := []Media{
118+
{Format: "CD", Pregap: &pregapTrack, Tracks: []Track{{ID: "regular-track"}}},
119+
}
120+
tracks := FlatTracks(media)
121+
assert.Len(t, tracks, 2)
122+
assert.Equal(t, "pregap-track", tracks[0].ID)
123+
assert.Equal(t, "regular-track", tracks[1].ID)
124+
})
125+
}

0 commit comments

Comments
 (0)