package release import "slices" // Comparing a file against a MusicBrainz track: shared by the importer's // check of a download and the library listing's match of an album (#5569). // LengthFits allows five seconds or 3%, whichever is more: remasters and // rips differ by a second or two, a different recording by far more. A // track MusicBrainz has no length for says nothing against the file. func LengthFits(fileMs, trackMs int) bool { if trackMs <= 0 { return true } if fileMs <= 0 { return false } tol := max(5000, trackMs*3/100) d := fileMs - trackMs return d <= tol && -d <= tol } // TitleAgrees: the same words, or one title holding all of the other's // ("Get Lucky (Radio Edit)" holds "Get Lucky"). func TitleAgrees(a, b string) bool { ta, tb := Tokens(a), Tokens(b) if len(ta) == 0 || len(tb) == 0 { return false } return subset(ta, tb) || subset(tb, ta) } func subset(small, big []string) bool { for _, w := range small { if !slices.Contains(big, w) { return false } } return true }