Get album info (when available) from Last.fm, add getAlbumInfo endpoint (#2061)
* lastfm album.getInfo, getAlbuminfo(2) endpoints * ... for description and reduce not found log level * address first comments * return all images * Update migration timestamp * Handle a few edge cases * Add CoverArtPriority option to retrieve albumart from external sources * Make agents methods more descriptive * Use Last.fm name consistently Co-authored-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -81,7 +80,7 @@ func (a *artistReader) Reader(ctx context.Context) (io.ReadCloser, string, error
|
||||
return selectImageReader(ctx, a.artID,
|
||||
fromArtistFolder(ctx, a.artistFolder, "artist.*"),
|
||||
fromExternalFile(ctx, a.files, "artist.*"),
|
||||
fromExternalSource(ctx, a.artist, a.em),
|
||||
fromArtistExternalSource(ctx, a.artist, a.em),
|
||||
fromArtistPlaceholder(),
|
||||
)
|
||||
}
|
||||
@@ -106,24 +105,3 @@ func fromArtistFolder(ctx context.Context, artistFolder string, pattern string)
|
||||
return f, filePath, err
|
||||
}
|
||||
}
|
||||
|
||||
func fromExternalSource(ctx context.Context, ar model.Artist, em core.ExternalMetadata) sourceFunc {
|
||||
return func() (io.ReadCloser, string, error) {
|
||||
imageUrl, err := em.ArtistImage(ctx, ar.ID)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
hc := http.Client{Timeout: 5 * time.Second}
|
||||
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, imageUrl.String(), nil)
|
||||
resp, err := hc.Do(req)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
resp.Body.Close()
|
||||
return nil, "", fmt.Errorf("error retrieveing cover from %s: %s", imageUrl, resp.Status)
|
||||
}
|
||||
return resp.Body, imageUrl.String(), nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user