No files matched your search
@@ -21,6 +21,7 @@ import (
|
||||
"go.senan.xyz/gonic/server/ctrlsubsonic/spec"
|
||||
"go.senan.xyz/gonic/server/ctrlsubsonic/specid"
|
||||
"go.senan.xyz/gonic/server/ctrlsubsonic/specidpaths"
|
||||
"go.senan.xyz/gonic/tags"
|
||||
"go.senan.xyz/gonic/transcode"
|
||||
)
|
||||
|
||||
@@ -49,7 +50,7 @@ func (c *Controller) ServeGetCoverArt(w http.ResponseWriter, r *http.Request) *s
|
||||
_, err = os.Stat(cachePath)
|
||||
switch {
|
||||
case os.IsNotExist(err):
|
||||
reader, err := coverFor(c.dbc, c.artistInfoCache, id)
|
||||
reader, err := coverFor(c.dbc, c.artistInfoCache, c.tagReader, id)
|
||||
if err != nil {
|
||||
return spec.NewError(10, "couldn't find cover %q: %v", id, err)
|
||||
}
|
||||
@@ -76,7 +77,7 @@ var (
|
||||
)
|
||||
|
||||
// TODO: can we use specidpaths.Locate here?
|
||||
func coverFor(dbc *db.DB, artistInfoCache *artistinfocache.ArtistInfoCache, id specid.ID) (io.ReadCloser, error) {
|
||||
func coverFor(dbc *db.DB, artistInfoCache *artistinfocache.ArtistInfoCache, tagReader tags.Reader, id specid.ID) (io.ReadCloser, error) {
|
||||
switch id.Type {
|
||||
case specid.Album:
|
||||
return coverForAlbum(dbc, id.Value)
|
||||
@@ -86,6 +87,8 @@ func coverFor(dbc *db.DB, artistInfoCache *artistinfocache.ArtistInfoCache, id s
|
||||
return coverForPodcast(dbc, id.Value)
|
||||
case specid.PodcastEpisode:
|
||||
return coverForPodcastEpisode(dbc, id.Value)
|
||||
case specid.Track:
|
||||
return coverForTrack(dbc, tagReader, id.Value)
|
||||
default:
|
||||
return nil, errCoverNotFound
|
||||
}
|
||||
@@ -150,6 +153,29 @@ func coverForPodcastEpisode(dbc *db.DB, id int) (*os.File, error) {
|
||||
return os.Open(filepath.Join(pe.Podcast.RootDir, pe.Podcast.Image))
|
||||
}
|
||||
|
||||
func coverForTrack(dbc *db.DB, tagReader tags.Reader, id int) (io.ReadCloser, error) {
|
||||
var tr db.Track
|
||||
err := dbc.
|
||||
Preload("Album").
|
||||
First(&tr, id).
|
||||
Error
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("select track: %w", err)
|
||||
}
|
||||
|
||||
absPath := tr.AbsPath()
|
||||
|
||||
cover, err := tagReader.ReadCover(absPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read cover: %w", err)
|
||||
}
|
||||
if len(cover) == 0 {
|
||||
return nil, errCoverEmpty
|
||||
}
|
||||
|
||||
return io.NopCloser(bytes.NewReader(cover)), nil
|
||||
}
|
||||
|
||||
func coverScaleAndSave(reader io.Reader, cachePath string, size int) error {
|
||||
src, err := imaging.Decode(reader)
|
||||
if err != nil {
|
||||
|
||||
@@ -30,6 +30,8 @@ func NewAlbumByFolder(f *db.Album) *Album {
|
||||
}
|
||||
if f.Cover != "" {
|
||||
a.CoverID = f.SID()
|
||||
} else if f.EmbeddedCoverTrackID != nil {
|
||||
a.CoverID = f.EmbeddedCoverTrackSID()
|
||||
}
|
||||
return a
|
||||
}
|
||||
@@ -52,7 +54,10 @@ func NewTCAlbumByFolder(f *db.Album) *TrackChild {
|
||||
}
|
||||
if f.Cover != "" {
|
||||
trCh.CoverID = f.SID()
|
||||
} else if f.EmbeddedCoverTrackID != nil {
|
||||
trCh.CoverID = f.EmbeddedCoverTrackSID()
|
||||
}
|
||||
|
||||
return trCh
|
||||
}
|
||||
|
||||
@@ -86,7 +91,10 @@ func NewTCTrackByFolder(t *db.Track, parent *db.Album) *TrackChild {
|
||||
}
|
||||
if parent.Cover != "" {
|
||||
trCh.CoverID = parent.SID()
|
||||
} else if parent.EmbeddedCoverTrackID != nil {
|
||||
trCh.CoverID = parent.EmbeddedCoverTrackSID()
|
||||
}
|
||||
|
||||
if t.Album != nil {
|
||||
trCh.Album = t.Album.RightPath
|
||||
trCh.AlbumID = t.Album.SID()
|
||||
@@ -163,6 +171,8 @@ func NewArtistByFolder(f *db.Album) *Artist {
|
||||
}
|
||||
if f.Cover != "" {
|
||||
a.CoverID = f.SID()
|
||||
} else if f.EmbeddedCoverTrackID != nil {
|
||||
a.CoverID = f.EmbeddedCoverTrackSID()
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ func NewAlbumByTags(a *db.Album, artists []*db.Artist) *Album {
|
||||
}
|
||||
if a.Cover != "" {
|
||||
ret.CoverID = a.SID()
|
||||
} else if a.EmbeddedCoverTrackID != nil {
|
||||
ret.CoverID = a.EmbeddedCoverTrackSID()
|
||||
}
|
||||
if a.AlbumStar != nil {
|
||||
ret.Starred = &a.AlbumStar.StarDate
|
||||
@@ -90,6 +92,8 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
|
||||
}
|
||||
if album.Cover != "" {
|
||||
ret.CoverID = album.SID()
|
||||
} else if album.EmbeddedCoverTrackID != nil {
|
||||
ret.CoverID = album.EmbeddedCoverTrackSID()
|
||||
}
|
||||
if t.TrackStar != nil {
|
||||
ret.Starred = &t.TrackStar.StarDate
|
||||
|
||||
Reference in New Issue
Block a user