Resize if requested
This commit is contained in:
@@ -2,6 +2,7 @@ package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"image"
|
||||
|
||||
"github.com/navidrome/navidrome/consts"
|
||||
"github.com/navidrome/navidrome/log"
|
||||
@@ -11,50 +12,93 @@ import (
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = FDescribe("Artwork", func() {
|
||||
var _ = Describe("Artwork", func() {
|
||||
var aw *artwork
|
||||
var ds model.DataStore
|
||||
ctx := log.NewContext(context.TODO())
|
||||
var alOnlyEmbed, alEmbedNotFound model.Album
|
||||
var alOnlyEmbed, alEmbedNotFound, alOnlyExternal, alExternalNotFound, alAllOptions model.Album
|
||||
|
||||
BeforeEach(func() {
|
||||
ds = &tests.MockDataStore{MockedTranscoding: &tests.MockTranscodingRepo{}}
|
||||
alOnlyEmbed = model.Album{ID: "222", Name: "Only embed", EmbedArtPath: "tests/fixtures/test.mp3"}
|
||||
alEmbedNotFound = model.Album{ID: "333", Name: "Embed not found", EmbedArtPath: "tests/fixtures/NON_EXISTENT.mp3"}
|
||||
// {ID: "666", Name: "All options", EmbedArtPath: "tests/fixtures/test.mp3",
|
||||
// ImageFiles: "tests/fixtures/cover.jpg:tests/fixtures/front.png"},
|
||||
//})
|
||||
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"}
|
||||
alAllOptions = model.Album{ID: "666", Name: "All options", EmbedArtPath: "tests/fixtures/test.mp3",
|
||||
ImageFiles: "tests/fixtures/cover.jpg:tests/fixtures/front.png",
|
||||
}
|
||||
aw = NewArtwork(ds).(*artwork)
|
||||
})
|
||||
|
||||
When("cover art is not found", func() {
|
||||
BeforeEach(func() {
|
||||
ds.Album(ctx).(*tests.MockAlbumRepo).SetData(model.Albums{
|
||||
alOnlyEmbed,
|
||||
Context("Albums", func() {
|
||||
Context("ID not found", func() {
|
||||
BeforeEach(func() {
|
||||
ds.Album(ctx).(*tests.MockAlbumRepo).SetData(model.Albums{
|
||||
alOnlyEmbed,
|
||||
})
|
||||
})
|
||||
It("returns placeholder if album is not in the DB", func() {
|
||||
_, path, err := aw.get(context.Background(), "al-999-0", 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(path).To(Equal(consts.PlaceholderAlbumArt))
|
||||
})
|
||||
})
|
||||
It("returns placeholder if album is not in the DB", func() {
|
||||
_, path, err := aw.get(context.Background(), "al-999-0", 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(path).To(Equal(consts.PlaceholderAlbumArt))
|
||||
Context("Embed images", func() {
|
||||
BeforeEach(func() {
|
||||
ds.Album(ctx).(*tests.MockAlbumRepo).SetData(model.Albums{
|
||||
alOnlyEmbed,
|
||||
alEmbedNotFound,
|
||||
})
|
||||
})
|
||||
It("returns embed cover", func() {
|
||||
_, path, err := aw.get(context.Background(), alOnlyEmbed.CoverArtID().String(), 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(path).To(Equal("tests/fixtures/test.mp3"))
|
||||
})
|
||||
It("returns placeholder if embed path is not available", func() {
|
||||
_, path, err := aw.get(context.Background(), alEmbedNotFound.CoverArtID().String(), 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(path).To(Equal(consts.PlaceholderAlbumArt))
|
||||
})
|
||||
})
|
||||
Context("External images", func() {
|
||||
BeforeEach(func() {
|
||||
ds.Album(ctx).(*tests.MockAlbumRepo).SetData(model.Albums{
|
||||
alOnlyExternal,
|
||||
alAllOptions,
|
||||
})
|
||||
})
|
||||
It("returns external cover", func() {
|
||||
_, path, err := aw.get(context.Background(), alOnlyExternal.CoverArtID().String(), 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(path).To(Equal("tests/fixtures/front.png"))
|
||||
})
|
||||
It("returns the first image if more than one is available", func() {
|
||||
_, path, err := aw.get(context.Background(), alAllOptions.CoverArtID().String(), 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(path).To(Equal("tests/fixtures/cover.jpg"))
|
||||
})
|
||||
It("returns placeholder if external file is not available", func() {
|
||||
_, path, err := aw.get(context.Background(), alExternalNotFound.CoverArtID().String(), 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(path).To(Equal(consts.PlaceholderAlbumArt))
|
||||
})
|
||||
})
|
||||
})
|
||||
When("album has only embed images", func() {
|
||||
Context("Resize", func() {
|
||||
BeforeEach(func() {
|
||||
ds.Album(ctx).(*tests.MockAlbumRepo).SetData(model.Albums{
|
||||
alOnlyEmbed,
|
||||
alEmbedNotFound,
|
||||
alOnlyExternal,
|
||||
})
|
||||
})
|
||||
It("returns embed cover", func() {
|
||||
_, path, err := aw.get(context.Background(), alOnlyEmbed.CoverArtID().String(), 0)
|
||||
It("returns external cover resized", func() {
|
||||
r, path, err := aw.get(context.Background(), alOnlyExternal.CoverArtID().String(), 300)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(path).To(Equal("tests/fixtures/test.mp3"))
|
||||
})
|
||||
It("returns placeholder if embed path is not available", func() {
|
||||
_, path, err := aw.get(context.Background(), alEmbedNotFound.CoverArtID().String(), 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(path).To(Equal(consts.PlaceholderAlbumArt))
|
||||
Expect(path).To(Equal("tests/fixtures/front.png@300"))
|
||||
img, _, err := image.Decode(r)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(img.Bounds().Size().X).To(Equal(300))
|
||||
Expect(img.Bounds().Size().Y).To(Equal(300))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user