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 } }