#798: Spotify Free as a rate-limit bridge for connected users (hybrid)

When Spotify Free is enabled, it now also bridges an official rate-limit ban for
authenticated users instead of stalling — search already did this (the gate
opens on no-auth OR rate-limit); this extends it to the enrichment worker.

- spotify_worker: the rate-limit guard now sleeps only when free CAN'T cover
  (is_spotify_metadata_available() is False). Purely additive — with Spotify
  Free off, that's False during a ban and the worker sleeps exactly as before.
  Verified: toggle OFF + rate-limited -> sleeps (original); toggle ON -> bridges.
- Reframed the Settings toggle so connected users know it also covers rate-limits
  ("Use Spotify Free when Spotify is unavailable or rate-limited").

The official auth path is untouched; free never runs while authed Spotify works
normally.
This commit is contained in:
BoulderBadgeDad 2026-06-05 14:00:50 -07:00
parent 2667eaec87
commit a387814deb
2 changed files with 10 additions and 4 deletions

View file

@ -186,8 +186,14 @@ class SpotifyWorker:
interruptible_sleep(self._stop_event, 1)
continue
# Rate limit guard — if globally rate limited, sleep until ban expires
if self.client.is_rate_limited():
# Rate limit guard — if globally rate limited, sleep until ban
# expires. EXCEPT: when Spotify Free is available it bridges the
# ban (is_spotify_metadata_available() is True via the no-creds
# source, and the client routes there), so we keep enriching
# instead of stalling. Purely additive: with Spotify Free off,
# is_spotify_metadata_available() is False during a ban and this
# sleeps exactly as before.
if self.client.is_rate_limited() and not self.client.is_spotify_metadata_available():
info = self.client.get_rate_limit_info()
remaining = info['remaining_seconds'] if info else 60
logger.debug(f"Spotify globally rate limited, sleeping {remaining}s...")

View file

@ -3847,9 +3847,9 @@
<div class="form-group">
<label class="checkbox-label">
<input type="checkbox" id="metadata-spotify-free">
<span>Enable Spotify Free (no credentials)</span>
<span>Use Spotify Free when Spotify is unavailable or rate-limited</span>
</label>
<div class="callback-help">Fetch Spotify metadata without API credentials, for when you can't or don't want to connect Spotify. Unofficial &amp; best-effort (it can break if Spotify changes), and it can't search albums by name or access your library — only used when Spotify isn't authenticated.</div>
<div class="callback-help">Fetches Spotify metadata without API credentials. Works two ways: as a full Spotify source if you haven't connected your account, and as a bridge that keeps search &amp; enrichment going when your connected Spotify hits a rate-limit. Unofficial &amp; best-effort (can break if Spotify changes); it can't search albums by name or access your library, and never runs while your authenticated Spotify is working normally.</div>
</div>
<div class="callback-info">
<div class="callback-help">Choose the primary source for artist, album, and track metadata. Spotify needs an active session — or enable Spotify Free above. Discogs requires a personal token. MusicBrainz is always available but rate-limited to 1 req/sec.</div>