mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Small optimization in genre mapping
This commit is contained in:
parent
0c0bd2967d
commit
73a2271cdd
2 changed files with 10 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue