Files
minstrel/internal/providers/lastfm.go
T
bvandeusenandClaude Opus 5.5 d8abc457e7 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>
2026-11-26 13:00:51 -05:00

34 lines
1.2 KiB
Go

package providers
import "time"
// LastfmBaseURL is Last.fm's API root, used by both the cover-art and the
// tag Last.fm providers.
const LastfmBaseURL = "https://ws.audioscrobbler.com/2.0/"
// LastfmPacer spaces every Last.fm request this server makes, whichever
// family asks: 4 a second, under Last.fm's 5 a second per key. Each
// family pacing on its own could reach 8 a second when an admin uses one
// key for both.
var LastfmPacer = NewInterval(250 * time.Millisecond)
// lastfmTransientCodes are the JSON error codes that mean "try again"
// rather than "no data": 8 operation failed, 11 and 16 service temporarily
// unavailable, 29 rate limit exceeded.
var lastfmTransientCodes = map[int]bool{8: true, 11: true, 16: true, 29: true}
// LastfmError maps the error field Last.fm returns in a 200 body. 0 is no
// error. A transient code is ErrTransient, so the row is retried on a later
// pass instead of settling as having nothing from Last.fm; anything else (6
// not found, 10 invalid key, …) is ErrNotFound, and the chain moves on.
func LastfmError(code int) error {
switch {
case code == 0:
return nil
case lastfmTransientCodes[code]:
return ErrTransient
default:
return ErrNotFound
}
}