Revert: Small optimization in genre mapping

This commit is contained in:
Deluan 2021-10-04 17:28:45 -04:00
parent a6311259fd
commit f0c11916ca
2 changed files with 8 additions and 3 deletions

View file

@ -141,12 +141,12 @@ func (s mediaFileMapper) mapGenres(genres []string) (string, model.Genres) {
var result model.Genres var result model.Genres
unique := map[string]struct{}{} unique := map[string]struct{}{}
var all []string var all []string
separators := conf.Server.Scanner.GenreSeparators + " "
for i := range genres { for i := range genres {
gs := strings.FieldsFunc(genres[i], func(r rune) bool { gs := strings.FieldsFunc(genres[i], func(r rune) bool {
return strings.ContainsRune(separators, r) return strings.ContainsRune(conf.Server.Scanner.GenreSeparators, r)
}) })
for _, g := range gs { for j := range gs {
g := strings.TrimSpace(gs[j])
key := strings.ToLower(g) key := strings.ToLower(g)
if _, ok := unique[key]; ok { if _, ok := unique[key]; ok {
continue continue

View file

@ -67,5 +67,10 @@ var _ = Describe("mapping", func() {
Expect(gs[1].Name).To(Equal("Dance")) Expect(gs[1].Name).To(Equal("Dance"))
Expect(gs[2].Name).To(Equal("Electronic")) Expect(gs[2].Name).To(Equal("Electronic"))
}) })
It("does not break on spaces", func() {
_, gs := mapper.mapGenres([]string{"New Wave"})
Expect(gs).To(HaveLen(1))
Expect(gs[0].Name).To(Equal("New Wave"))
})
}) })
}) })