Skip to content

Commit

Permalink
Small optimization in genre mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Sep 21, 2021
1 parent 0c0bd29 commit 73a2271
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions scanner/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ func (s mediaFileMapper) mapGenres(genres []string) (string, model.Genres) {
var result model.Genres
unique := map[string]struct{}{}
var all []string
separators := conf.Server.Scanner.GenreSeparators + " "
for i := range genres {
gs := strings.FieldsFunc(genres[i], func(r rune) bool {
return strings.ContainsRune(conf.Server.Scanner.GenreSeparators, r)
return strings.ContainsRune(separators, r)
})
for j := range gs {
g := strings.TrimSpace(gs[j])
for _, g := range gs {
key := strings.ToLower(g)
if _, ok := unique[key]; ok {
continue
Expand Down
7 changes: 7 additions & 0 deletions scanner/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,12 @@ var _ = Describe("mapping", func() {
Expect(gs[1].Name).To(Equal("Dance"))
Expect(gs[2].Name).To(Equal("Electronic"))
})
It("trims genres names", func() {
_, gs := mapper.mapGenres([]string{"Rock ; Dance", " Electronic "})
Expect(gs).To(HaveLen(3))
Expect(gs[0].Name).To(Equal("Rock"))
Expect(gs[1].Name).To(Equal("Dance"))
Expect(gs[2].Name).To(Equal("Electronic"))
})
})
})

0 comments on commit 73a2271

Please sign in to comment.