Authentication
The bot uses Spotify’s client credentials flow for server-to-server authentication. Set:src/utils/spotify.rs
Batch enrichment
The/songs command parses up to 10 opening and 10 ending themes, combines both sections for enrichment, and passes the complete batch to enrich_songs_with_spotify.
For each song with an artist, the integration:
- Checks Redis for a cached positive or negative result.
- Authenticates only when an uncached song needs a Spotify request.
- Reuses the authenticated Spotify client and access token for the remaining uncached songs in the batch.
- Makes at most one later authentication retry after a transient token failure.
- Restores the enriched songs to their opening and ending sections.
Search strategy
Annie Mei searches for the track and artist together:- Search with the romaji title.
- If Spotify returns no track and a kana title is available, search with the kana title using the same authenticated client.
- Use the first matching track URL, or display the song without a link.
tokio::task::spawn_blocking so it does not block Tokio’s async worker threads.
Redis caching
Spotify lookups share the bot’s Redis cache. The cache key remains compatible with earlier releases:- the Spotify URL for a successful match
Nonewhen an authenticated search produces no usable URL
Failure behavior
Spotify enrichment is optional. If Spotify cannot authenticate, times out, or returns no track, Annie Mei still displays the MyAnimeList song title, artist, and episode range when those fields are available.A missing Spotify link does not mean the theme song lookup failed. It means Annie Mei did not obtain a usable Spotify match for that song.
Dependency
The integration usesrspotify with its blocking ureq client and Rustls:
