Skip to content

🎧 Your Personal Streaming Service

Skip trying to read cover art from mediafile if it does not have one

Deluanbce7b163bae6
diff --git a/core/artwork.go b/core/artwork.go
index c1c992c87..38eb03446 100644
--- a/core/artwork.go
+++ b/core/artwork.go
@@ -113,11 +113,15 @@ func (a *artwork) extractMediaFileImage(ctx context.Context, artID model.Artwork
return nil, ""
}
- return extractImage(ctx, artID,
- fromTag(mf.Path),
- fromFFmpegTag(ctx, a.ffmpeg, mf.Path),
- a.fromAlbum(ctx, mf.AlbumCoverArtID()),
- )
+ var ff []fromFunc
+ if mf.HasCoverArt {
+ ff = []fromFunc{
+ fromTag(mf.Path),
+ fromFFmpegTag(ctx, a.ffmpeg, mf.Path),
+ }
+ }
+ ff = append(ff, a.fromAlbum(ctx, mf.AlbumCoverArtID()))
+ return extractImage(ctx, artID, ff...)
}
func (a *artwork) resizedFromOriginal(ctx context.Context, artID model.ArtworkID, size int) (io.ReadCloser, string, error) {
@@ -225,7 +229,13 @@ func fromFFmpegTag(ctx context.Context, ffmpeg ffmpeg.FFmpeg, path string) fromF
if err != nil {
return nil, ""
}
- return r, path
+ defer r.Close()
+ buf := new(bytes.Buffer)
+ _, err = io.Copy(buf, r)
+ if err != nil {
+ return nil, ""
+ }
+ return io.NopCloser(buf), path
}
}
diff --git a/core/artwork_internal_test.go b/core/artwork_internal_test.go
index e7ead1695..b8dfc917b 100644
--- a/core/artwork_internal_test.go
+++ b/core/artwork_internal_test.go
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"image"
+ "io"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
@@ -40,7 +41,7 @@ var _ = Describe("Artwork", func() {
conf.Server.ImageCacheSize = "0" // Disable cache
cache := GetImageCache()
- ffmpeg = tests.NewMockFFmpeg("")
+ ffmpeg = tests.NewMockFFmpeg("content from ffmpeg")
aw = NewArtwork(ds, cache, ffmpeg).(*artwork)
})
@@ -129,8 +130,9 @@ var _ = Describe("Artwork", func() {
Expect(path).To(Equal("tests/fixtures/test.mp3"))
})
It("returns embed cover if successfully extracted by ffmpeg", func() {
- _, path, err := aw.get(context.Background(), mfCorruptedCover.CoverArtID(), 0)
+ r, path, err := aw.get(context.Background(), mfCorruptedCover.CoverArtID(), 0)
Expect(err).ToNot(HaveOccurred())
+ Expect(io.ReadAll(r)).To(Equal([]byte("content from ffmpeg")))
Expect(path).To(Equal("tests/fixtures/test.ogg"))
})
It("returns album cover if cannot read embed artwork", func() {
diff --git a/tests/mock_ffmpeg.go b/tests/mock_ffmpeg.go
index 735b12914..aa21acae8 100644
--- a/tests/mock_ffmpeg.go
+++ b/tests/mock_ffmpeg.go
@@ -6,8 +6,6 @@ import (
"strings"
"sync"
- "github.com/navidrome/navidrome/consts"
- "github.com/navidrome/navidrome/resources"
"github.com/navidrome/navidrome/utils"
)
@@ -33,7 +31,7 @@ func (ff *MockFFmpeg) ExtractImage(ctx context.Context, path string) (io.ReadClo
if ff.Error != nil {
return nil, ff.Error
}
- return resources.FS().Open(consts.PlaceholderAlbumArt)
+ return ff, nil
}
func (ff *MockFFmpeg) Read(p []byte) (n int, err error) {