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:
@@ -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"))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user