mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-05 18:03:10 +03:00
Allowing album cover ids with prefix (al-)
This commit is contained in:
parent
9fd530b78a
commit
a7ccd76d54
@ -40,7 +40,7 @@ func (c *MediaRetrievalController) GetCoverArt() {
|
|||||||
switch {
|
switch {
|
||||||
case err == domain.ErrNotFound:
|
case err == domain.ErrNotFound:
|
||||||
beego.Error(err, "Id:", id)
|
beego.Error(err, "Id:", id)
|
||||||
c.SendError(responses.ErrorDataNotFound, "Directory not found")
|
c.SendError(responses.ErrorDataNotFound, "Cover not found")
|
||||||
case err != nil:
|
case err != nil:
|
||||||
beego.Error(err)
|
beego.Error(err)
|
||||||
c.SendError(responses.ErrorGeneric, "Internal Error")
|
c.SendError(responses.ErrorGeneric, "Internal Error")
|
||||||
|
@ -143,6 +143,7 @@ func (b *browser) buildAlbumDir(al *domain.Album, tracks domain.MediaFiles) *Dir
|
|||||||
Created: al.CreatedAt,
|
Created: al.CreatedAt,
|
||||||
Year: al.Year,
|
Year: al.Year,
|
||||||
Genre: al.Genre,
|
Genre: al.Genre,
|
||||||
|
CoverArt: al.CoverArtId,
|
||||||
}
|
}
|
||||||
|
|
||||||
dir.Entries = make(Entries, len(tracks))
|
dir.Entries = make(Entries, len(tracks))
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
_ "image/png"
|
_ "image/png"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/deluan/gosonic/domain"
|
"github.com/deluan/gosonic/domain"
|
||||||
"github.com/dhowden/tag"
|
"github.com/dhowden/tag"
|
||||||
@ -20,22 +21,44 @@ type Cover interface {
|
|||||||
|
|
||||||
type cover struct {
|
type cover struct {
|
||||||
mfileRepo domain.MediaFileRepository
|
mfileRepo domain.MediaFileRepository
|
||||||
|
albumRepo domain.AlbumRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCover(mr domain.MediaFileRepository) Cover {
|
func NewCover(mr domain.MediaFileRepository, alr domain.AlbumRepository) Cover {
|
||||||
return &cover{mr}
|
return &cover{mr, alr}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *cover) getCoverPath(id string) (string, error) {
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(id, "al-"):
|
||||||
|
id = id[3:]
|
||||||
|
al, err := c.albumRepo.Get(id)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return al.CoverArtPath, nil
|
||||||
|
default:
|
||||||
|
mf, err := c.mfileRepo.Get(id)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if mf.HasCoverArt {
|
||||||
|
return mf.Path, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", domain.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cover) Get(id string, size int, out io.Writer) error {
|
func (c *cover) Get(id string, size int, out io.Writer) error {
|
||||||
mf, err := c.mfileRepo.Get(id)
|
path, err := c.getCoverPath(id)
|
||||||
if err != nil && err != domain.ErrNotFound {
|
if err != nil && err != domain.ErrNotFound {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var reader io.Reader
|
var reader io.Reader
|
||||||
|
|
||||||
if err == nil && mf.HasCoverArt {
|
if err != domain.ErrNotFound {
|
||||||
reader, err = readFromTag(mf.Path)
|
reader, err = readFromTag(path)
|
||||||
} else {
|
} else {
|
||||||
var f *os.File
|
var f *os.File
|
||||||
f, err = os.Open("static/default_cover.jpg")
|
f, err = os.Open("static/default_cover.jpg")
|
||||||
|
@ -17,8 +17,9 @@ func TestCover(t *testing.T) {
|
|||||||
Init(t, false)
|
Init(t, false)
|
||||||
|
|
||||||
mockMediaFileRepo := persistence.CreateMockMediaFileRepo()
|
mockMediaFileRepo := persistence.CreateMockMediaFileRepo()
|
||||||
|
mockAlbumRepo := persistence.CreateMockAlbumRepo()
|
||||||
|
|
||||||
cover := engine.NewCover(mockMediaFileRepo)
|
cover := engine.NewCover(mockMediaFileRepo, mockAlbumRepo)
|
||||||
out := new(bytes.Buffer)
|
out := new(bytes.Buffer)
|
||||||
|
|
||||||
Convey("Subject: GetCoverArt Endpoint", t, func() {
|
Convey("Subject: GetCoverArt Endpoint", t, func() {
|
||||||
@ -70,6 +71,16 @@ func TestCover(t *testing.T) {
|
|||||||
So(img.Bounds().Max.Y, ShouldEqual, 100)
|
So(img.Bounds().Max.Y, ShouldEqual, 100)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Convey("When id is for an album", func() {
|
||||||
|
mockAlbumRepo.SetData(`[{"Id":"1","CoverArtPath":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
|
||||||
|
err := cover.Get("al-1", 0, out)
|
||||||
|
|
||||||
|
Convey("Then it should return the cover for the album", func() {
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(out.Bytes(), ShouldMatchMD5, "e859a71cd1b1aaeb1ad437d85b306668")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
Reset(func() {
|
Reset(func() {
|
||||||
mockMediaFileRepo.SetData("[]", 0)
|
mockMediaFileRepo.SetData("[]", 0)
|
||||||
mockMediaFileRepo.SetError(false)
|
mockMediaFileRepo.SetError(false)
|
||||||
|
@ -298,6 +298,7 @@ func (s *ItunesScanner) collectAlbums(t *itl.Track, mf *domain.MediaFile, ar *do
|
|||||||
|
|
||||||
if mf.HasCoverArt {
|
if mf.HasCoverArt {
|
||||||
al.CoverArtId = mf.Id
|
al.CoverArtId = mf.Id
|
||||||
|
al.CoverArtPath = mf.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
if al.PlayDate.IsZero() || t.PlayDateUTC.After(al.PlayDate) {
|
if al.PlayDate.IsZero() || t.PlayDateUTC.After(al.PlayDate) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user