Add Tag Player plugin for linking identifiers to media#2958
Add Tag Player plugin for linking identifiers to media#2958ztripez wants to merge 2 commits intomusic-assistant:devfrom
Conversation
| async def _create_db_table(self) -> None: | ||
| """Create the tagplayer mappings table if it doesn't exist.""" | ||
| await self.mass.music.database.execute( | ||
| f"""CREATE TABLE IF NOT EXISTS {DB_TABLE_TAGPLAYER}( | ||
| [tag_id] TEXT PRIMARY KEY, | ||
| [media_type] TEXT NOT NULL, | ||
| [item_id] INTEGER NOT NULL | ||
| );""" | ||
| ) |
There was a problem hiding this comment.
Why would you need a separate db ? You can simply use provider mappings to existing items.
There was a problem hiding this comment.
I don't,
I think i was so deep into my own thing it never occurred to me to use provider mappings.
| await self.mass.music.database.insert_or_replace( | ||
| DB_TABLE_TAGPLAYER, | ||
| {"tag_id": tag_id, "media_type": media_type.value, "item_id": item_id}, | ||
| ) |
There was a problem hiding this comment.
We cant accept music providers doing direct db modifications
| await self.mass.music.database.delete(DB_TABLE_TAGPLAYER, {"tag_id": tag_id}) | ||
| self.logger.debug("Unlinked tag '%s'", tag_id) | ||
| return {"status": "ok", "tag_id": tag_id} |
There was a problem hiding this comment.
See my previous comment - this is unacceptable. My suggestion would be that you add a provider mapping to an existing item with the available flag set to False (to prevent playback being attempted to the provider).
|
As you get closer to merging I will just need some text for the docs |
|
Just thinking out loud here.. Does it make sense that this functionality is implemented as a Thoughts? |
I never tested this but theoretically I think you can just add any provider mapping to items. Might be worth a test. |
|
Marking this PR as draft so we can keep track of which PRs needs our attention. Please mark as 'Ready for review' when you want us to have another look 🙏 . |
Do you want me to explore this instead? |
Complete rewrite based on reviewer feedback (marcelveldt, MarvinSchenkel): - Changed from MusicProvider to PluginProvider (plugin type) - Replaced custom SQLite table with provider mappings (available=False) - URI resolution uses existing get_library_item_by_prov_id SQL lookups - 5 API commands: link, unlink, get, list, play - 24 unit tests covering lifecycle, CRUD, playback, and parsing
2dda0ef to
36f814e
Compare
🔒 Dependency Security Report✅ No dependency changes detected in this PR. |
|
Rewrite complete! Based on the feedback from @marcelveldt and @MarvinSchenkel, this is now a PluginProvider that uses provider mappings instead of a custom SQLite table:
The 5 API commands ( 24 unit tests included. Ready for review! |
|
So my idea actually worked? |
| MediaType.ARTIST, | ||
| MediaType.RADIO, | ||
| MediaType.AUDIOBOOK, | ||
| MediaType.PODCAST, |
There was a problem hiding this comment.
Let's add the new MediaType.GENRE here as well?
| "description": "Link NFC tags, QR codes, or any identifier to media items for quick playback.", | ||
| "codeowners": ["@ztripez"], | ||
| "requirements": [], | ||
| "documentation": "https://music-assistant.io/music-providers/tagplayer/", |
There was a problem hiding this comment.
This should point to /plugins/ now
|
Few small things and then this should be good to go. Would be awesome if you can add some documentation, especially about how to set it up from a HA perspective as well. FYI, we moved the docs here since we launched a new website. Marking this as draft again, please set it to 'ready for review' when you want us to have another look. |
Summary
Adds a Tag Player plugin that links arbitrary identifiers (NFC tags, QR codes, or any string) to media items for quick playback.
Complete rewrite based on reviewer feedback from @marcelveldt and @MarvinSchenkel:
MusicProvider→PluginProvider(manifest type:plugin)available=False)get_library_item_by_prov_idSQL lookups — no custom DB codePersonal note
I built a tag player for my kids using NFC tags. Initially I made a Home Assistant automation that acted like an abomination of a tag database, but Music Assistant is already the source of truth for my media library — the tag mappings belong here.
How it works
Tags are stored as provider mappings on existing library items with
available=False(so MA never tries to stream through tagplayer). The tag ID becomes theitem_idin the mapping, and resolution uses the standardprovider_mappingstable lookup.API Commands
tagplayer/linktarget="playlist/42")tagplayer/unlinktagplayer/gettagplayer/listtagplayer/playURI format
tagplayer://<media_type>/<tag_id>— media type must match the linked item type (e.g.,tagplayer://playlist/party-mixfor a playlist tag).Usage example
Supported media types
Tracks, albums, playlists, artists, radio, audiobooks, podcasts
Tests
24 unit tests covering lifecycle, link/unlink/get/list, playback, error handling, and target parsing.