fix(lastfm): don't replace cached artist image with empty on refresh
last.fm intermittently omits the og:image meta tag from artist pages. previously this would overwrite a good cached image URL with empty, leaving artists without artwork until the next cache cycle
This commit is contained in:
No files matched your search
@@ -80,8 +80,9 @@ func (a *ArtistInfoCache) Lookup(ctx context.Context, artist *db.Artist) (*db.Ar
|
||||
}
|
||||
artistInfo.SetSimilarArtists(similar)
|
||||
|
||||
url, _ := a.lastfmClient.StealArtistImage(info.URL)
|
||||
if url, _ := a.lastfmClient.StealArtistImage(info.URL); url != "" {
|
||||
artistInfo.ImageURL = url
|
||||
}
|
||||
|
||||
topTracksResponse, err := a.lastfmClient.ArtistGetTopTracks(artist.Name)
|
||||
if err != nil {
|
||||
|
||||
@@ -203,6 +203,9 @@ func (c *Client) StealArtistImage(artistURL string) (string, error) {
|
||||
return "", fmt.Errorf("get artist url: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode/100 != 2 {
|
||||
return "", fmt.Errorf("get artist url: %s", resp.Status)
|
||||
}
|
||||
|
||||
node, err := html.Parse(resp.Body)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user