mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-17 15:48:39 +01:00
Better handling of album comments (#1013)
* Change album comment behaviour * Don't check first item * Fix previously imported album comments. * Remove song comments if album comment is present
This commit is contained in:
parent
4b5a5abe1b
commit
b671d0ff7b
6 changed files with 114 additions and 7 deletions
|
|
@ -263,15 +263,18 @@ func (r *albumRepository) refresh(ids ...string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Return the first non empty comment, if any
|
||||
func getComment(comments string, separator string) string {
|
||||
cs := strings.Split(comments, separator)
|
||||
for _, c := range cs {
|
||||
if c != "" {
|
||||
return c
|
||||
if len(cs) == 0 {
|
||||
return ""
|
||||
}
|
||||
first := cs[0]
|
||||
for _, c := range cs[1:] {
|
||||
if first != c {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return first
|
||||
}
|
||||
|
||||
func getMinYear(years string) int {
|
||||
|
|
|
|||
|
|
@ -96,8 +96,11 @@ var _ = Describe("AlbumRepository", func() {
|
|||
It("returns empty string if there are no comments", func() {
|
||||
Expect(getComment("", "")).To(Equal(""))
|
||||
})
|
||||
It("returns first occurrence of non-empty comment", func() {
|
||||
Expect(getComment(zwsp+zwsp+"first"+zwsp+"second", zwsp)).To(Equal("first"))
|
||||
It("returns empty string if comments are different", func() {
|
||||
Expect(getComment("first"+zwsp+"second", zwsp)).To(Equal(""))
|
||||
})
|
||||
It("returns comment if all comments are the same", func() {
|
||||
Expect(getComment("first"+zwsp+"first", zwsp)).To(Equal("first"))
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue