Fix artwork resolution when paths contains `:`. Fix #2137

This commit is contained in:
Deluan 2023-02-02 12:13:24 -05:00
parent f904784e67
commit 9b81aa4403
7 changed files with 16 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/tests"
@ -34,7 +35,7 @@ var _ = Describe("Artwork", func() {
alOnlyExternal = model.Album{ID: "444", Name: "Only external", ImageFiles: "tests/fixtures/front.png"}
alExternalNotFound = model.Album{ID: "555", Name: "External not found", ImageFiles: "tests/fixtures/NON_EXISTENT.png"}
alMultipleCovers = model.Album{ID: "666", Name: "All options", EmbedArtPath: "tests/fixtures/test.mp3",
ImageFiles: "tests/fixtures/cover.jpg:tests/fixtures/front.png",
ImageFiles: "tests/fixtures/cover.jpg" + consts.Zwsp + "tests/fixtures/front.png",
}
mfWithEmbed = model.MediaFile{ID: "22", Path: "tests/fixtures/test.mp3", HasCoverArt: true, AlbumID: "222"}
mfWithoutEmbed = model.MediaFile{ID: "44", Path: "tests/fixtures/test.ogg", AlbumID: "444"}

View File

@ -13,6 +13,7 @@ import (
"github.com/Masterminds/squirrel"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/core"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
@ -49,12 +50,12 @@ func newArtistReader(ctx context.Context, artwork *artwork, artID model.ArtworkI
var paths []string
for _, al := range als {
files = append(files, al.ImageFiles)
paths = append(paths, filepath.SplitList(al.Paths)...)
paths = append(paths, splitList(al.Paths)...)
if a.cacheKey.lastUpdate.Before(al.UpdatedAt) {
a.cacheKey.lastUpdate = al.UpdatedAt
}
}
a.files = strings.Join(files, string(filepath.ListSeparator))
a.files = strings.Join(files, consts.Zwsp)
a.artistFolder = utils.LongestCommonPrefix(paths)
if !strings.HasSuffix(a.artistFolder, string(filepath.Separator)) {
a.artistFolder, _ = filepath.Split(a.artistFolder)

View File

@ -52,9 +52,13 @@ func (f sourceFunc) String() string {
return name
}
func splitList(s string) []string {
return strings.Split(s, consts.Zwsp)
}
func fromExternalFile(ctx context.Context, files string, pattern string) sourceFunc {
return func() (io.ReadCloser, string, error) {
for _, file := range filepath.SplitList(files) {
for _, file := range splitList(files) {
_, name := filepath.Split(file)
match, err := filepath.Match(pattern, strings.ToLower(name))
if err != nil {

View File

@ -59,7 +59,7 @@ func upAddAlbumPathsDirs(filePaths string) string {
}
slices.Sort(dirs)
dirs = slices.Compact(dirs)
return strings.Join(dirs, string(filepath.ListSeparator))
return strings.Join(dirs, consts.Zwsp)
}
func downAddAlbumPaths(tx *sql.Tx) error {

View File

@ -151,7 +151,7 @@ func (mfs MediaFiles) ToAlbum() Album {
a.EmbedArtPath = m.Path
}
}
a.Paths = strings.Join(mfs.Dirs(), string(filepath.ListSeparator))
a.Paths = strings.Join(mfs.Dirs(), consts.Zwsp)
comments = slices.Compact(comments)
if len(comments) == 1 {
a.Comment = comments[0]

View File

@ -5,6 +5,7 @@ import (
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/consts"
. "github.com/navidrome/navidrome/model"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
@ -52,7 +53,7 @@ var _ = Describe("MediaFiles", func() {
Expect(album.CatalogNum).To(Equal("CatalogNum"))
Expect(album.Compilation).To(BeTrue())
Expect(album.EmbedArtPath).To(Equal("/music2/file2.mp3"))
Expect(album.Paths).To(Equal("/music1:/music2"))
Expect(album.Paths).To(Equal("/music1" + consts.Zwsp + "/music2"))
})
})
Context("Aggregated attributes", func() {

View File

@ -8,6 +8,7 @@ import (
"time"
"github.com/Masterminds/squirrel"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/core/artwork"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
@ -121,7 +122,7 @@ func (r *refresher) getImageFiles(dirs []string) (string, time.Time) {
updatedAt = stats.ImagesUpdatedAt
}
}
return strings.Join(imageFiles, string(filepath.ListSeparator)), updatedAt
return strings.Join(imageFiles, consts.Zwsp), updatedAt
}
func (r *refresher) refreshArtists(ctx context.Context, ids ...string) error {