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:
sentriz
2026-04-14 10:37:46 +01:00
parent 5daf95cdeb
commit ec457fb380
2 changed files with 6 additions and 2 deletions

No files matched your search

+3 -2
View File
@@ -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)
artistInfo.ImageURL = url
if url, _ := a.lastfmClient.StealArtistImage(info.URL); url != "" {
artistInfo.ImageURL = url
}
topTracksResponse, err := a.lastfmClient.ArtistGetTopTracks(artist.Name)
if err != nil {
+3
View File
@@ -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 {