Skip to content

🎧 Your Personal Streaming Service

Make sure album is updated if external cover changes

Deluan9ec349dce04c
diff --git a/core/artwork.go b/core/artwork.go
index a103ce20a..b6b1b0b77 100644
--- a/core/artwork.go
+++ b/core/artwork.go
@@ -182,7 +182,9 @@ func (a *artwork) fromCoverArtPriority(ctx context.Context, priority string, al
ff = append(ff, fromTag(al.EmbedArtPath), fromFFmpegTag(ctx, a.ffmpeg, al.EmbedArtPath))
continue
}
- ff = append(ff, fromExternalFile(ctx, al.ImageFiles, pattern))
+ if al.ImageFiles != "" {
+ ff = append(ff, fromExternalFile(ctx, al.ImageFiles, pattern))
+ }
}
return ff
}
@@ -201,6 +203,7 @@ func fromExternalFile(ctx context.Context, files string, pattern string) fromFun
}
f, err := os.Open(file)
if err != nil {
+ log.Warn(ctx, "Could not open cover art file", "file", file, err)
continue
}
return f, file, err
diff --git a/scanner/refresher.go b/scanner/refresher.go
index 2c782c87d..15d1186af 100644
--- a/scanner/refresher.go
+++ b/scanner/refresher.go
@@ -5,6 +5,7 @@ import (
"fmt"
"path/filepath"
"strings"
+ "time"
"github.com/Masterminds/squirrel"
"github.com/navidrome/navidrome/log"
@@ -93,7 +94,11 @@ func (r *refresher) refreshAlbums(ids ...string) error {
for _, group := range grouped {
songs := model.MediaFiles(group)
a := songs.ToAlbum()
- a.ImageFiles = r.getImageFiles(songs.Dirs())
+ var updatedAt time.Time
+ a.ImageFiles, updatedAt = r.getImageFiles(songs.Dirs())
+ if updatedAt.After(a.UpdatedAt) {
+ a.UpdatedAt = updatedAt
+ }
err := repo.Put(&a)
if err != nil {
return err
@@ -102,14 +107,19 @@ func (r *refresher) refreshAlbums(ids ...string) error {
return nil
}
-func (r *refresher) getImageFiles(dirs []string) string {
+func (r *refresher) getImageFiles(dirs []string) (string, time.Time) {
var imageFiles []string
+ var updatedAt time.Time
for _, dir := range dirs {
- for _, img := range r.dirMap[dir].Images {
+ stats := r.dirMap[dir]
+ for _, img := range stats.Images {
imageFiles = append(imageFiles, filepath.Join(dir, img))
}
+ if stats.ImagesUpdatedAt.After(updatedAt) {
+ updatedAt = stats.ImagesUpdatedAt
+ }
}
- return strings.Join(imageFiles, string(filepath.ListSeparator))
+ return strings.Join(imageFiles, string(filepath.ListSeparator)), updatedAt
}
func (r *refresher) refreshArtists(ids ...string) error {
diff --git a/scanner/walk_dir_tree.go b/scanner/walk_dir_tree.go
index b4a4a658b..b32ba11f3 100644
--- a/scanner/walk_dir_tree.go
+++ b/scanner/walk_dir_tree.go
@@ -20,6 +20,7 @@ type (
Path string
ModTime time.Time
Images []string
+ ImagesUpdatedAt time.Time
HasPlaylist bool
AudioFilesCount uint32
}
@@ -93,12 +94,15 @@ func loadDir(ctx context.Context, dirPath string) ([]string, *dirStats, error) {
if fileInfo.ModTime().After(stats.ModTime) {
stats.ModTime = fileInfo.ModTime()
}
- if utils.IsAudioFile(entry.Name()) {
+ switch {
+ case utils.IsAudioFile(entry.Name()):
stats.AudioFilesCount++
- } else {
- stats.HasPlaylist = stats.HasPlaylist || model.IsValidPlaylist(entry.Name())
- if utils.IsImageFile(entry.Name()) {
- stats.Images = append(stats.Images, entry.Name())
+ case model.IsValidPlaylist(entry.Name()):
+ stats.HasPlaylist = true
+ case utils.IsImageFile(entry.Name()):
+ stats.Images = append(stats.Images, entry.Name())
+ if fileInfo.ModTime().After(stats.ImagesUpdatedAt) {
+ stats.ImagesUpdatedAt = fileInfo.ModTime()
}
}
}
diff --git a/utils/cache/file_caches.go b/utils/cache/file_caches.go
index 6cb3a42cd..00680ebe5 100644
--- a/utils/cache/file_caches.go
+++ b/utils/cache/file_caches.go
@@ -127,7 +127,7 @@ func (fc *fileCache) Get(ctx context.Context, arg Item) (*CachedStream, error) {
log.Warn(ctx, "Error removing key from cache", "cache", fc.name, "key", key, err)
}
} else {
- log.Trace(ctx, "File stored in cache", "cache", fc.name, "key", key)
+ log.Trace(ctx, "File successfully stored in cache", "cache", fc.name, "key", key)
}
}()
}