🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Small refactoring
Deluan11bef060a371
diff --git a/persistence/artist_repository.go b/persistence/artist_repository.goindex 945179085..e1c7134c6 100644--- a/persistence/artist_repository.go+++ b/persistence/artist_repository.go@@ -141,7 +141,7 @@ func (r *artistRepository) toModels(dba []dbArtist) model.Artists {}func (r *artistRepository) getIndexKey(a *model.Artist) string {- name := strings.ToLower(str.NoArticle(a.Name))+ name := strings.ToLower(str.RemoveArticle(a.Name))for k, v := range r.indexGroups {key := strings.ToLower(k)if strings.HasPrefix(name, key) {diff --git a/utils/str/sanitize_strings.go b/utils/str/sanitize_strings.goindex 9a72206e0..de28c9fd1 100644--- a/utils/str/sanitize_strings.go+++ b/utils/str/sanitize_strings.go@@ -8,6 +8,7 @@ import ("github.com/deluan/sanitize""github.com/microcosm-cc/bluemonday"+ "github.com/navidrome/navidrome/conf")var quotesRegex = regexp.MustCompile("[“”‘’'\"\\[\\(\\{\\]\\)\\}]")@@ -46,5 +47,16 @@ func SanitizeFieldForSorting(originalValue string) string {func SanitizeFieldForSortingNoArticle(originalValue string) string {v := strings.TrimSpace(sanitize.Accents(originalValue))- return strings.ToLower(NoArticle(v))+ return strings.ToLower(RemoveArticle(v))+}++func RemoveArticle(name string) string {+ articles := strings.Split(conf.Server.IgnoredArticles, " ")+ for _, a := range articles {+ n := strings.TrimPrefix(name, a+" ")+ if n != name {+ return n+ }+ }+ return name}diff --git a/utils/str/sanitize_strings_test.go b/utils/str/sanitize_strings_test.goindex e623dd5ed..9f0d3f793 100644--- a/utils/str/sanitize_strings_test.go+++ b/utils/str/sanitize_strings_test.go@@ -63,4 +63,32 @@ var _ = Describe("Sanitize Strings", func() {Expect(str.SanitizeFieldForSortingNoArticle("Õ Blésq Blom")).To(Equal("blesq blom"))})})++ Describe("RemoveArticle", func() {+ Context("Empty articles list", func() {+ BeforeEach(func() {+ conf.Server.IgnoredArticles = ""+ })+ It("returns empty if string is empty", func() {+ Expect(str.RemoveArticle("")).To(BeEmpty())+ })+ It("returns same string", func() {+ Expect(str.RemoveArticle("The Beatles")).To(Equal("The Beatles"))+ })+ })+ Context("Default articles", func() {+ BeforeEach(func() {+ conf.Server.IgnoredArticles = "The El La Los Las Le Les Os As O A"+ })+ It("returns empty if string is empty", func() {+ Expect(str.RemoveArticle("")).To(BeEmpty())+ })+ It("remove prefix article from string", func() {+ Expect(str.RemoveArticle("Os Paralamas do Sucesso")).To(Equal("Paralamas do Sucesso"))+ })+ It("does not remove article if it is part of the first word", func() {+ Expect(str.RemoveArticle("Thelonious Monk")).To(Equal("Thelonious Monk"))+ })+ })+ })})diff --git a/utils/str/str.go b/utils/str/str.goindex b52a8cb53..3c40c927a 100644--- a/utils/str/str.go+++ b/utils/str/str.go@@ -2,8 +2,6 @@ package strimport ("strings"-- "github.com/navidrome/navidrome/conf")func Clear(name string) string {@@ -18,17 +16,6 @@ func Clear(name string) string {return r.Replace(name)}-func NoArticle(name string) string {- articles := strings.Split(conf.Server.IgnoredArticles, " ")- for _, a := range articles {- n := strings.TrimPrefix(name, a+" ")- if n != name {- return n- }- }- return name-}-func LongestCommonPrefix(list []string) string {if len(list) == 0 {return ""diff --git a/utils/str/str_test.go b/utils/str/str_test.goindex 64df3493a..8fe47e30a 100644--- a/utils/str/str_test.go+++ b/utils/str/str_test.go@@ -1,51 +1,22 @@package str_testimport (- "github.com/navidrome/navidrome/conf""github.com/navidrome/navidrome/utils/str". "github.com/onsi/ginkgo/v2". "github.com/onsi/gomega")-var _ = Describe("Clean", func() {- DescribeTable("replaces some Unicode chars with their equivalent ASCII",- func(input, expected string) {- Expect(str.Clear(input)).To(Equal(expected))- },- Entry("k-os", "k–os", "k-os"),- Entry("k‐os", "k‐os", "k-os"),- Entry(`"Weird" Al Yankovic`, "“Weird” Al Yankovic", `"Weird" Al Yankovic`),- Entry("Single quotes", "‘Single’ quotes", "'Single' quotes"),- )-})--var _ = Describe("Strings", func() {- Describe("NoArticle", func() {- Context("Empty articles list", func() {- BeforeEach(func() {- conf.Server.IgnoredArticles = ""- })- It("returns empty if string is empty", func() {- Expect(str.NoArticle("")).To(BeEmpty())- })- It("returns same string", func() {- Expect(str.NoArticle("The Beatles")).To(Equal("The Beatles"))- })- })- Context("Default articles", func() {- BeforeEach(func() {- conf.Server.IgnoredArticles = "The El La Los Las Le Les Os As O A"- })- It("returns empty if string is empty", func() {- Expect(str.NoArticle("")).To(BeEmpty())- })- It("remove prefix article from string", func() {- Expect(str.NoArticle("Os Paralamas do Sucesso")).To(Equal("Paralamas do Sucesso"))- })- It("does not remove article if it is part of the first word", func() {- Expect(str.NoArticle("Thelonious Monk")).To(Equal("Thelonious Monk"))- })- })+var _ = Describe("String Utils", func() {+ Describe("Clear", func() {+ DescribeTable("replaces some Unicode chars with their equivalent ASCII",+ func(input, expected string) {+ Expect(str.Clear(input)).To(Equal(expected))+ },+ Entry("k-os", "k–os", "k-os"),+ Entry("k‐os", "k‐os", "k-os"),+ Entry(`"Weird" Al Yankovic`, "“Weird” Al Yankovic", `"Weird" Al Yankovic`),+ Entry("Single quotes", "‘Single’ quotes", "'Single' quotes"),+ )})Describe("LongestCommonPrefix", func() {@@ -53,7 +24,6 @@ var _ = Describe("Strings", func() {Expect(str.LongestCommonPrefix(testPaths)).To(Equal("/Music/iTunes 1/iTunes Media/Music/"))})})-})var testPaths = []string{