fix(providers): Last.fm's rate limit retries art later, and both Last.fm sources share one pace (#8002)
The cover-art Last.fm provider read every JSON error code as "no art", so a burst of rate-limit (29) or service-unavailable (8, 11, 16) answers marked albums and artists as having nothing on Last.fm. The tag provider already retried those. providers.LastfmError is now the one mapping, used by both. Each family also paced Last.fm on its own at 4 requests a second, so together they could reach 8 a second against the 5-per-key limit when an admin uses one key for both. Both now wait on providers.LastfmPacer. The client's own spacing is a providers.Interval, so a pace can be shared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,13 +12,10 @@ import (
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/providers"
|
||||
)
|
||||
|
||||
// lastfmBaseURL is a var (not const) so tests can override it.
|
||||
var lastfmBaseURL = "https://ws.audioscrobbler.com/2.0/"
|
||||
// lastfmBaseURL is a var (not const) so tests can point it at a test server.
|
||||
var lastfmBaseURL = providers.LastfmBaseURL
|
||||
|
||||
const (
|
||||
// lastfmMinPeriod throttles to 4 req/s under their 5/s per-key ceiling.
|
||||
lastfmMinPeriod = 250 * time.Millisecond
|
||||
|
||||
lastfmMaxRetries = 3
|
||||
)
|
||||
|
||||
@@ -51,7 +48,7 @@ func init() {
|
||||
client: providers.NewHTTPClient(providers.HTTPOptions{
|
||||
Name: "lastfm",
|
||||
HTTPClient: &http.Client{Timeout: 30 * time.Second},
|
||||
MinInterval: lastfmMinPeriod,
|
||||
Pacer: providers.LastfmPacer,
|
||||
MaxRetries: lastfmMaxRetries,
|
||||
TreatAuthAsTransient: true,
|
||||
}),
|
||||
@@ -116,7 +113,10 @@ func (p *lastfmProvider) FetchArtistArt(ctx context.Context, ref ArtistRef) (thu
|
||||
if err := p.client.GetJSON(ctx, lastfmBaseURL+"?"+q.Encode(), &resp); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if resp.Error != 0 || resp.Artist.Name == "" {
|
||||
if err := providers.LastfmError(resp.Error); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if resp.Artist.Name == "" {
|
||||
return nil, nil, ErrNotFound
|
||||
}
|
||||
imgURL := pickLargestImage(resp.Artist.Image)
|
||||
@@ -162,7 +162,10 @@ func (p *lastfmProvider) FetchAlbumCover(ctx context.Context, ref AlbumRef) ([]b
|
||||
if err := p.client.GetJSON(ctx, lastfmBaseURL+"?"+q.Encode(), &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.Error != 0 || resp.Album.Name == "" {
|
||||
if err := providers.LastfmError(resp.Error); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.Album.Name == "" {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
imgURL := pickLargestImage(resp.Album.Image)
|
||||
|
||||
Reference in New Issue
Block a user