Skip to content

Metadata, plugin and audio analysis providers

These three provider types each subclass a base class in music_assistant/models/. As for a music provider, you pass a set of ProviderFeature values to the constructor, and the server only calls the methods of the features in it.

A metadata provider fills in what the music sources leave out, such as artwork, biographies and lyrics. The metadata controller asks it when it refreshes an item: see Library, sync and metadata.

  • Subclass MetadataProvider.
  • Declare ARTIST_METADATA, ALBUM_METADATA, TRACK_METADATA or PLAYLIST_METADATA, and implement the matching get_artist_metadata(), get_album_metadata(), get_track_metadata() or get_playlist_metadata(). Each returns MediaItemMetadata, or None when you have nothing.
  • priority orders the providers, lower first. Set is_local for a provider that reads local storage instead of an online service, and report rate_limited while you hold requests back.
  • Similar tracks and artists, artist top tracks and recommendations are optional features of their own.

There is no demo metadata provider. Learn from fanarttv (artwork from an online service) or lrclib (lyrics).

A plugin adds a feature to the core. Subclass PluginProvider and pick the features:

Feature What you implement Example
AUDIO_SOURCE get_audio_sources() returns AudioSource items a player can play; get_stream_details() and, for a custom stream, get_audio_stream() deliver the audio airplay_receiver
AI_QUERY get_ai_engines() and ai_query(); for images also get_image_engines() and ai_generate_image() openai_compatible
TTS get_tts_engines() and get_tts_message(), which returns StreamDetails with a URL or a local file that stays playable openai_tts
SCROBBLE on_media_item_played(), which gets a progress report of what plays; ScrobblerHelper in helpers/scrobbler.py does the usual now-playing and scrobble handling lastfm_scrobble
  • Audio sources. get_stream_details() has no side effects, as the server also calls it to load ahead. Claim an exclusive source in on_source_selected() and release it in on_source_unselected(). The docstrings in media_capabilities.py hold the streaming contract.
  • Engines. One plugin can offer several AI, image or speech engines, such as one per Home Assistant entity. The user picks one in the settings of the provider that uses it; your provider gets back the engine’s own id.
  • Search, browse and recommendations are optional features of a plugin too.
  • Stored player ids. A provider of any type that stores a player id resolves it with mass.players.resolve_player_id() where it reads it, as the player may have been merged into another one. The players README covers legacy ids, keep_player() and PLAYER_REMOVED.

List audio_source, ai, tts or scrobble in provides of the manifest when your provider has the matching feature in every config. A plugin can also add menu actions, tools for AI assistants and a page.

Start from _demo_plugin_provider: an audio source and a scrobbler, with a menu action, an MCP tool and a page.

An audio analysis provider listens to the audio itself. It reads the raw PCM of a track while it plays, or during a background scan, and derives data from it: loudness, tempo, beats and downbeats, key, energy or a fingerprint. It gets a copy of the decoded audio and never changes what is played.

The server keeps the results per item and per analysis provider in audio_analysis.db (see Where data lives). Other parts use them for volume normalization, smart crossfades, similar tracks and matching metadata.

The server has four of them, each with a page in the user documentation: Loudness Analysis, Smart Fades, Sonic Analysis and AcoustID Lookup.

Subclass AudioAnalysisProvider and implement:

  • _start_analysis(): set up a session; return False to refuse it.
  • process_pcm_chunk(): handle one chunk. Await all its work, as that holds the audio source back, and keep little in memory.
  • _finalize(): return the AudioAnalysisData, or None to skip. The base class stores it and then calls post_analysis().

Further:

  • Raise analysis_version when your algorithm changes: tracks analyzed with an older version are analyzed again.
  • media_types says what you are offered (tracks by default), max_analysis_duration skips longer items, and has_unloadable_models with _load_models() and _free_models() frees heavy models while idle.
  • post_analysis() runs for playback and for background scans alike: it checks itself that streamdetails.path is a file it may write to.
  • Background scans only cover local files, because of the usage policy. Leave that restriction in place.

Start from _demo_audio_analysis_provider, and learn from loudness_analysis.

Music Assistant is a project of the Open Home Foundation.