mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-13 10:47:19 +03:00
Skip trying to read cover art from mediafile if it does not have one
This commit is contained in:
parent
2923f01cd9
commit
bce7b163ba
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user