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:
caiocotts
2021-04-24 21:40:55 -04:00
committed by GitHub
parent 4b5a5abe1b
commit b671d0ff7b
6 changed files with 114 additions and 7 deletions
+8 -5
View File
@@ -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 {
+5 -2
View File
@@ -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"))
})
})