mass_queue icon indicating copy to clipboard operation
mass_queue copied to clipboard

get_artist_tracks returns empty for many artists — uses the wrong MA server command (generic artist_tracks instead of curated top_tracks)

Open patch3r opened this issue 4 months ago • 0 comments

Summary

mass_queue.get_artist_tracks frequently returns an empty tracks list for artists that clearly have listenable/curated top-track data — confirmed by comparing against Music Assistant's own web UI, which shows a fully populated "Top tracks" section for the exact same artist.

Note: this was investigated with AI assistance (tracing the Music Assistant server source and testing live against a real HA/MA instance), reviewed and verified by me before posting. Happy to answer any follow-up questions myself.

Environment

  • Music Assistant server: 2.9.9
  • Providers: Apple Music + local library
  • mass_queue: current main

Reproduction

Artist "Daft Punk" — library-linked (library://artist/155), with a provider mapping to apple_music (item 5468295).

service: mass_queue.get_artist_tracks
data:
  uri: "library://artist/155"
  config_entry_id: "<config entry id>"

Returns tracks: [].

Music Assistant's own web UI, for the same artist, shows a populated "Top tracks — On Apple Music" section with 10 curated songs (I Feel It Coming, One More Time, Harder Better Faster Stronger, Get Lucky, …).

Root cause

I traced this through the Music Assistant server source (music_assistant/controllers/music/media/artists.py). There are two distinct, separately-registered API commands:

  • music/artists/artist_tracks → ArtistsController.tracks() → provider.get_artist_tracks() — a generic, full-discography listing (every track from every album the artist has). This is what mass_queue.get_artist_tracks currently calls, via music_assistant_client's Music.get_artist_tracks().
  • music/artists/top_tracks → ArtistsController.top_tracks() → provider.get_artist_toptracks() — the curated top-tracks/chart listing (e.g. Apple Music's own top-songs API endpoint). Per the server docstring, "for a library item, the top tracks of all the artist's providers are aggregated (and deduplicated)". This is what MA's own frontend uses, and isn't currently wrapped by music_assistant_client (I called it via a raw send_command).

Separately: get_artist_tracks and get_album_tracks in actions.py only ever try mappings[0] (the artist's/album's first provider mapping) instead of trying all linked providers. So even when using the right command, if the first mapping happens to point at a provider without the relevant data (e.g. library, which has no chart/popularity data), the call comes back empty even though another linked provider (e.g. apple_music) has it.

Proposed fix

I have a patch (happy to open as a PR) that:

  1. Switches get_artist_tracks to call music/artists/top_tracks (via send_command, since music_assistant_client doesn't wrap it yet) instead of the generic music/artists/artist_tracks.
  2. Prefers the aggregated provider_instance_id_or_domain="library" call when the artist has a library entry (aggregates + dedupes across all linked providers in one call), then falls back to iterating each individual provider mapping.
  3. If no provider mapping has top-tracks data at all, falls back to the artist's albums (via a new get_artist_albums service — music/artists/artist_albums, also iterating mappings) so callers still get something playable instead of an empty result.
  4. Applies the same "iterate all mappings instead of just mappings[0]" fix to get_album_tracks.

Verified live against a real HA + MA 2.9.9 instance: music/artists/top_tracks with provider_instance_id_or_domain="library" returns the same curated tracklist MA's own UI shows for the artist.

One compatibility note: get_artist_tracks's page parameter would no longer be used, since top_tracks isn't a paginated command. Worth flagging in case anyone relies on it — though it's worth noting this was already effectively broken: the existing code passes page as the third positional argument to client.music.get_artist_tracks(), but that position is actually in_library_only: bool, not a page number, so it likely never did what it looked like it did.

Let me know if you'd rather I take a different approach here (e.g. a new dedicated get_artist_top_tracks service instead of changing get_artist_tracks's existing behavior, to avoid any compatibility break) — happy to adjust before opening a PR either way.

patch3r avatar Jul 18 '26 13:07 patch3r