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:
Kendall Garner
2023-01-18 01:22:54 +00:00
committed by GitHub
parent 5564f00838
commit 93adda66d9
33 changed files with 797 additions and 188 deletions
+1 -23
View File
@@ -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
}
}