Remove CoverArtID, fix tests

This commit is contained in:
Deluan 2022-12-19 14:11:43 -05:00 committed by Deluan Quintão
parent 38bde0ddba
commit c36e77d41f
6 changed files with 35 additions and 126 deletions

View File

@ -2,28 +2,23 @@ package core
import (
"context"
"image"
"os"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/tests"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Artwork", func() {
var artwork Artwork
var ds model.DataStore
ctx := log.NewContext(context.TODO())
BeforeEach(func() {
ds = &tests.MockDataStore{MockedTranscoding: &tests.MockTranscodingRepo{}}
ds.Album(ctx).(*tests.MockAlbumRepo).SetData(model.Albums{
{ID: "222", EmbedArtId: "123", EmbedArtPath: "tests/fixtures/test.mp3"},
{ID: "333", EmbedArtId: ""},
{ID: "444", EmbedArtId: "444", EmbedArtPath: "tests/fixtures/cover.jpg"},
{ID: "222", EmbedArtPath: "tests/fixtures/test.mp3"},
{ID: "333"},
{ID: "444", EmbedArtPath: "tests/fixtures/cover.jpg"},
})
ds.MediaFile(ctx).(*tests.MockMediaFileRepo).SetData(model.MediaFiles{
{ID: "123", AlbumID: "222", Path: "tests/fixtures/test.mp3", HasCoverArt: true},
@ -31,114 +26,4 @@ var _ = Describe("Artwork", func() {
})
})
Context("Cache is configured", func() {
BeforeEach(func() {
conf.Server.DataFolder, _ = os.MkdirTemp("", "file_caches")
conf.Server.ImageCacheSize = "100MB"
cache := GetImageCache()
Eventually(func() bool { return cache.Ready(context.TODO()) }).Should(BeTrue())
artwork = NewArtwork(ds, cache)
})
AfterEach(func() {
_ = os.RemoveAll(conf.Server.DataFolder)
})
It("retrieves the external artwork art for an album", func() {
r, err := artwork.Get(ctx, "al-444", 0)
Expect(err).To(BeNil())
_, format, err := image.Decode(r)
Expect(err).To(BeNil())
Expect(format).To(Equal("jpeg"))
Expect(r.Close()).To(BeNil())
})
It("retrieves the embedded artwork art for an album", func() {
r, err := artwork.Get(ctx, "al-222", 0)
Expect(err).To(BeNil())
_, format, err := image.Decode(r)
Expect(err).To(BeNil())
Expect(format).To(Equal("jpeg"))
Expect(r.Close()).To(BeNil())
})
It("returns the default artwork if album does not have artwork", func() {
r, err := artwork.Get(ctx, "al-333", 0)
Expect(err).To(BeNil())
_, format, err := image.Decode(r)
Expect(err).To(BeNil())
Expect(format).To(Equal("png"))
Expect(r.Close()).To(BeNil())
})
It("returns the default artwork if album is not found", func() {
r, err := artwork.Get(ctx, "al-0101", 0)
Expect(err).To(BeNil())
_, format, err := image.Decode(r)
Expect(err).To(BeNil())
Expect(format).To(Equal("png"))
Expect(r.Close()).To(BeNil())
})
It("retrieves the original artwork art from a media_file", func() {
r, err := artwork.Get(ctx, "123", 0)
Expect(err).To(BeNil())
img, format, err := image.Decode(r)
Expect(err).To(BeNil())
Expect(format).To(Equal("jpeg"))
Expect(img.Bounds().Size().X).To(Equal(600))
Expect(img.Bounds().Size().Y).To(Equal(600))
Expect(r.Close()).To(BeNil())
})
It("retrieves the album artwork art if media_file does not have one", func() {
r, err := artwork.Get(ctx, "456", 0)
Expect(err).To(BeNil())
_, format, err := image.Decode(r)
Expect(err).To(BeNil())
Expect(format).To(Equal("jpeg"))
Expect(r.Close()).To(BeNil())
})
It("retrieves the album artwork by album id", func() {
r, err := artwork.Get(ctx, "222", 0)
Expect(err).To(BeNil())
_, format, err := image.Decode(r)
Expect(err).To(BeNil())
Expect(format).To(Equal("jpeg"))
Expect(r.Close()).To(BeNil())
})
It("resized artwork art as requested", func() {
r, err := artwork.Get(ctx, "123", 200)
Expect(err).To(BeNil())
img, format, err := image.Decode(r)
Expect(err).To(BeNil())
Expect(format).To(Equal("jpeg"))
Expect(img.Bounds().Size().X).To(Equal(200))
Expect(img.Bounds().Size().Y).To(Equal(200))
Expect(r.Close()).To(BeNil())
})
Context("Errors", func() {
It("returns err if gets error from album table", func() {
ds.Album(ctx).(*tests.MockAlbumRepo).SetError(true)
_, err := artwork.Get(ctx, "al-222", 0)
Expect(err).To(MatchError("Error!"))
})
It("returns err if gets error from media_file table", func() {
ds.MediaFile(ctx).(*tests.MockMediaFileRepo).SetError(true)
_, err := artwork.Get(ctx, "123", 0)
Expect(err).To(MatchError("Error!"))
})
})
})
})

View File

@ -0,0 +1,27 @@
package migrations
import (
"database/sql"
"github.com/pressly/goose"
)
func init() {
goose.AddMigration(upRemoveCoverArtId, downRemoveCoverArtId)
}
func upRemoveCoverArtId(tx *sql.Tx) error {
_, err := tx.Exec(`
alter table album drop column cover_art_id;
alter table album rename column cover_art_path to embed_art_path
`)
if err != nil {
return err
}
notice(tx, "A full rescan needs to be performed to import all album images")
return forceFullRescan(tx)
}
func downRemoveCoverArtId(tx *sql.Tx) error {
return nil
}

View File

@ -7,8 +7,7 @@ type Album struct {
ID string `structs:"id" json:"id" orm:"column(id)"`
Name string `structs:"name" json:"name"`
EmbedArtPath string `structs:"cover_art_path" json:"coverArtPath"`
EmbedArtId string `structs:"cover_art_id" json:"coverArtId"`
EmbedArtPath string `structs:"embed_art_path" json:"embedArtPath"`
ArtistID string `structs:"artist_id" json:"artistId" orm:"column(artist_id)"`
Artist string `structs:"artist" json:"artist"`
AlbumArtistID string `structs:"album_artist_id" json:"albumArtistId" orm:"column(album_artist_id)"`

View File

@ -135,8 +135,7 @@ func (mfs MediaFiles) ToAlbum() Album {
m.Album, m.AlbumArtist, m.Artist,
m.SortAlbumName, m.SortAlbumArtistName, m.SortArtistName,
m.DiscSubtitle)
if m.HasCoverArt && a.EmbedArtId == "" {
a.EmbedArtId = m.ID
if m.HasCoverArt && a.EmbedArtPath == "" {
a.EmbedArtPath = m.Path
}
}

View File

@ -51,7 +51,6 @@ var _ = Describe("MediaFiles", func() {
Expect(album.MbzAlbumComment).To(Equal("MbzAlbumComment"))
Expect(album.CatalogNum).To(Equal("CatalogNum"))
Expect(album.Compilation).To(BeTrue())
Expect(album.EmbedArtId).To(Equal("2"))
Expect(album.EmbedArtPath).To(Equal("/music/file.mp3"))
})
})

View File

@ -46,9 +46,9 @@ var (
)
var (
albumSgtPeppers = model.Album{ID: "101", Name: "Sgt Peppers", Artist: "The Beatles", OrderAlbumName: "sgt peppers", AlbumArtistID: "3", Genre: "Rock", Genres: model.Genres{genreRock}, EmbedArtId: "1", EmbedArtPath: P("/beatles/1/sgt/a day.mp3"), SongCount: 1, MaxYear: 1967, FullText: " beatles peppers sgt the"}
albumAbbeyRoad = model.Album{ID: "102", Name: "Abbey Road", Artist: "The Beatles", OrderAlbumName: "abbey road", AlbumArtistID: "3", Genre: "Rock", Genres: model.Genres{genreRock}, EmbedArtId: "2", EmbedArtPath: P("/beatles/1/come together.mp3"), SongCount: 1, MaxYear: 1969, FullText: " abbey beatles road the"}
albumRadioactivity = model.Album{ID: "103", Name: "Radioactivity", Artist: "Kraftwerk", OrderAlbumName: "radioactivity", AlbumArtistID: "2", Genre: "Electronic", Genres: model.Genres{genreElectronic, genreRock}, EmbedArtId: "3", EmbedArtPath: P("/kraft/radio/radio.mp3"), SongCount: 2, FullText: " kraftwerk radioactivity"}
albumSgtPeppers = model.Album{ID: "101", Name: "Sgt Peppers", Artist: "The Beatles", OrderAlbumName: "sgt peppers", AlbumArtistID: "3", Genre: "Rock", Genres: model.Genres{genreRock}, EmbedArtPath: P("/beatles/1/sgt/a day.mp3"), SongCount: 1, MaxYear: 1967, FullText: " beatles peppers sgt the"}
albumAbbeyRoad = model.Album{ID: "102", Name: "Abbey Road", Artist: "The Beatles", OrderAlbumName: "abbey road", AlbumArtistID: "3", Genre: "Rock", Genres: model.Genres{genreRock}, EmbedArtPath: P("/beatles/1/come together.mp3"), SongCount: 1, MaxYear: 1969, FullText: " abbey beatles road the"}
albumRadioactivity = model.Album{ID: "103", Name: "Radioactivity", Artist: "Kraftwerk", OrderAlbumName: "radioactivity", AlbumArtistID: "2", Genre: "Electronic", Genres: model.Genres{genreElectronic, genreRock}, EmbedArtPath: P("/kraft/radio/radio.mp3"), SongCount: 2, FullText: " kraftwerk radioactivity"}
testAlbums = model.Albums{
albumSgtPeppers,
albumAbbeyRoad,