Files

107 lines
3.4 KiB
Go

package musicbrainz
import (
"naviwatcher/internal/database"
)
// FilterOptions holds per-artist type filtering preferences.
type FilterOptions struct {
IgnoreSingles bool
IgnoreCompilations bool
IgnoreLive bool
IgnoreRemix bool
}
// hasSliceType reports whether the slice contains any of the wanted values.
func hasSliceType(types []string, wanted ...string) bool {
for _, s := range types {
for _, w := range wanted {
if s == w {
return true
}
}
}
return false
}
// ApplyTypeToggles filters releases based on the IgnoreSingles and IgnoreCompilations flags.
// Implements canonical filtering logic:
//
// IgnoreSingles filters: Type == "Single" OR Type == "EP" OR SecondaryTypes contains "Single" OR "EP"
// IgnoreCompilations filters: Type == "Compilation" OR SecondaryTypes contains "Compilation"
// IgnoreLive filters: Type == "Live" OR SecondaryTypes contains "Live"
// IgnoreRemix filters: Type == "Remix" OR SecondaryTypes contains "Remix"
func ApplyTypeToggles(releases []database.ExternalRelease, opts FilterOptions) []database.ExternalRelease {
var result []database.ExternalRelease
for _, release := range releases {
// Apply IgnoreSingles filtering: filter out if Type is Single/EP OR SecondaryTypes contains Single/EP
if opts.IgnoreSingles {
if release.Type == "Single" || release.Type == "EP" || hasSliceType(release.SecondaryTypes, "Single", "EP") {
continue
}
}
// Apply IgnoreCompilations filtering: filter out if Type is Compilation OR SecondaryTypes contains Compilation
if opts.IgnoreCompilations {
if release.Type == "Compilation" || hasSliceType(release.SecondaryTypes, "Compilation") {
continue
}
}
// Apply IgnoreLive filtering: filter out if Type is Live OR SecondaryTypes contains Live
if opts.IgnoreLive {
if release.Type == "Live" || hasSliceType(release.SecondaryTypes, "Live") {
continue
}
}
// Apply IgnoreRemix filtering: filter out if Type is Remix OR SecondaryTypes contains Remix
if opts.IgnoreRemix {
if release.Type == "Remix" || hasSliceType(release.SecondaryTypes, "Remix") {
continue
}
}
result = append(result, release)
}
return result
}
// ApplyTypeTogglesToReleaseGroups applies the same IgnoreSingles/IgnoreCompinators filtering logic
// to a slice of ReleaseGroup objects.
func ApplyTypeTogglesToReleaseGroups(groups []ReleaseGroup, opts FilterOptions) []ReleaseGroup {
var result []ReleaseGroup
for _, rg := range groups {
// Apply IgnoreSingles filtering: filter out if Type is Single/EP OR SecondaryTypes contains Single/EP
if opts.IgnoreSingles {
if rg.Type == "Single" || rg.Type == "EP" || hasSliceType(rg.SecondaryTypes, "Single", "EP") {
continue
}
}
// Apply IgnoreCompilations filtering: filter out if Type is Compilation OR SecondaryTypes contains Compilation
if opts.IgnoreCompilations {
if rg.Type == "Compilation" || hasSliceType(rg.SecondaryTypes, "Compilation") {
continue
}
}
// Apply IgnoreLive filtering: filter out if Type is Live OR SecondaryTypes contains Live
if opts.IgnoreLive {
if rg.Type == "Live" || hasSliceType(rg.SecondaryTypes, "Live") {
continue
}
}
// Apply IgnoreRemix filtering: filter out if Type is Remix OR SecondaryTypes contains Remix
if opts.IgnoreRemix {
if rg.Type == "Remix" || hasSliceType(rg.SecondaryTypes, "Remix") {
continue
}
}
result = append(result, rg)
}
return result
}