mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +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
|
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(conf.Server.Scanner.GenreSeparators, r)
|
return strings.ContainsRune(separators, r)
|
||||||
})
|
})
|
||||||
for j := range gs {
|
for _, g := 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
|
||||||
|
|
|
@ -60,5 +60,12 @@ 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("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