Skip to main content
Annie Mei uses the MyAnimeList API to fetch opening and ending theme song information for anime. This data supplements the metadata from AniList with detailed theme song listings.

Endpoint

The MyAnimeList API v2 is accessed via:
The mal_id is obtained from the AniList API response (idMal field).

Authentication

Annie Mei authenticates requests with the X-MAL-CLIENT-ID header. The current implementation uses a single environment variable:
  • MAL_CLIENT_ID - Your MyAnimeList API client ID
Register for API access at MyAnimeList API Config.

Response Model

The API response is deserialized into the MalResponse struct:
Source: src/models/mal_response.rs:11-33

Song Text Format

The SongInfo.text field contains structured information in this format:

Parsing Logic

The bot parses the following components from each song text:
  1. Song Number: Extracted from #N: prefix
  2. Song Name: Text between quotes (" or ')
  3. Romaji vs Kana: Text before parentheses is romaji, text in parentheses is kana/native
  4. Artists: Text after “by” and before episode range
  5. Episode Range: Text in parentheses starting with “(ep”
Source: src/models/mal_response.rs:147-188

Example Response

Data Transformations

Display Formatting

Songs are formatted for Discord embeds with the following features:
Formatted output example:
Source: src/models/mal_response.rs:199-201

Spotify Integration

For each song, the bot attempts to find a matching Spotify track:
If found, the song title becomes a clickable link to Spotify. See the Spotify API page for details. Source: src/models/mal_response.rs:64-72

Artist Name Truncation

When more than 3 artists are listed, the display truncates to the first 3 and adds “and more”:
Source: src/models/mal_response.rs:128-132

List Truncation

Only the first 10 opening and ending themes are displayed to avoid Discord embed size limits:
Source: src/models/mal_response.rs:203-213

Usage Example

Error Handling

When song data is unavailable or parsing fails:
  • Missing opening/ending themes return "No information available"
  • Failed song name parsing returns "No information available"
  • Missing artist names are omitted from display
  • Missing episode ranges are omitted from display
Source: src/models/mal_response.rs:155-157

Rate Limiting

MyAnimeList enforces API rate limits. The bot should implement:
  • Request throttling
  • Response caching (especially for popular anime)
  • Graceful error handling for 429 Too Many Requests
Note: The current implementation does not include explicit rate limiting logic. Consider adding this for production use.