🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Allowing album cover ids with prefix (al-)
Deluana7ccd76d54fa
diff --git a/api/media_retrieval.go b/api/media_retrieval.goindex 414334556..5f3537698 100644--- a/api/media_retrieval.go+++ b/api/media_retrieval.go@@ -40,7 +40,7 @@ func (c *MediaRetrievalController) GetCoverArt() {switch {case err == domain.ErrNotFound:beego.Error(err, "Id:", id)- c.SendError(responses.ErrorDataNotFound, "Directory not found")+ c.SendError(responses.ErrorDataNotFound, "Cover not found")case err != nil:beego.Error(err)c.SendError(responses.ErrorGeneric, "Internal Error")diff --git a/engine/browser.go b/engine/browser.goindex 8cd4ebd05..2f22ea4ac 100644--- a/engine/browser.go+++ b/engine/browser.go@@ -143,6 +143,7 @@ func (b *browser) buildAlbumDir(al *domain.Album, tracks domain.MediaFiles) *DirCreated: al.CreatedAt,Year: al.Year,Genre: al.Genre,+ CoverArt: al.CoverArtId,}dir.Entries = make(Entries, len(tracks))diff --git a/engine/cover.go b/engine/cover.goindex cdb40ee41..5a10c0347 100644--- a/engine/cover.go+++ b/engine/cover.go@@ -8,6 +8,7 @@ import (_ "image/png""io""os"+ "strings""github.com/deluan/gosonic/domain""github.com/dhowden/tag"@@ -20,22 +21,44 @@ type Cover interface {type cover struct {mfileRepo domain.MediaFileRepository+ albumRepo domain.AlbumRepository}-func NewCover(mr domain.MediaFileRepository) Cover {- return &cover{mr}+func NewCover(mr domain.MediaFileRepository, alr domain.AlbumRepository) Cover {+ 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 {- mf, err := c.mfileRepo.Get(id)+ path, err := c.getCoverPath(id)if err != nil && err != domain.ErrNotFound {return err}var reader io.Reader- if err == nil && mf.HasCoverArt {- reader, err = readFromTag(mf.Path)+ if err != domain.ErrNotFound {+ reader, err = readFromTag(path)} else {var f *os.Filef, err = os.Open("static/default_cover.jpg")diff --git a/engine/cover_test.go b/engine/cover_test.goindex aeab41445..953713db6 100644--- a/engine/cover_test.go+++ b/engine/cover_test.go@@ -17,8 +17,9 @@ func TestCover(t *testing.T) {Init(t, false)mockMediaFileRepo := persistence.CreateMockMediaFileRepo()+ mockAlbumRepo := persistence.CreateMockAlbumRepo()- cover := engine.NewCover(mockMediaFileRepo)+ cover := engine.NewCover(mockMediaFileRepo, mockAlbumRepo)out := new(bytes.Buffer)Convey("Subject: GetCoverArt Endpoint", t, func() {@@ -70,6 +71,16 @@ func TestCover(t *testing.T) {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() {mockMediaFileRepo.SetData("[]", 0)mockMediaFileRepo.SetError(false)diff --git a/scanner/itunes_scanner.go b/scanner/itunes_scanner.goindex 09f20184d..55ba52a31 100644--- a/scanner/itunes_scanner.go+++ b/scanner/itunes_scanner.go@@ -298,6 +298,7 @@ func (s *ItunesScanner) collectAlbums(t *itl.Track, mf *domain.MediaFile, ar *doif mf.HasCoverArt {al.CoverArtId = mf.Id+ al.CoverArtPath = mf.Path}if al.PlayDate.IsZero() || t.PlayDateUTC.After(al.PlayDate) {