From 941d1a135dd7b03834576855e8e9fdaa24c4e406 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Mon, 24 Aug 2026 17:12:36 +0200 Subject: feat(node): Music app node-side — indexing, MusicBrainz enrichment, protocol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements the node half of docs/musicbay.md against MNP 0.8: - IndexEntry gains artist/album/track_no (reuses duration/thumb_hash/ display_title, already generic). New musicbrainz_config/_enabled and music_meta_req/_resp message pairs, mirroring the TMDB shape. - title_parse.parse_track_filename: track-number-prefix + title parsing, fallback-only (embedded tags are the primary source, unlike Videos). - indexer.enrich_audio.AudioEnricher: mutagen-based tag/embedded-cover extraction through its own bounded pool (asyncio.to_thread, no subprocess — no ffmpeg-shaped deadlock risk). Gated on "music" in a group's enabled_apps rather than a video_root-style scoped folder. - musicbrainz.py: MusicBrainzClient — no API key (unlike TMDB), just a self-imposed ~1 req/s pace and a configurable, non-default User-Agent contact string; inert (no calls at all) when no contact is configured, never sends an unidentified client. - media_cache.py: file_mbid/mbid_meta tables alongside the existing TMDB ones, cover art reusing the thumbs table via a synthetic musicbrainz:{mbid} id, pruned on file deletion. - roster.py/ops.py/webrtc_server.py: musicbrainz_contact (node-wide) and musicbrainz_enabled (per-group, from the start) as signed operator settings, ALLOWED_APPS gains "music", _do_music_meta_request resolves and caches a release-level MusicBrainz match per (artist, album). - daemon.py: AudioEnricher/MusicBrainzClient wired alongside the video ones; a group's existing library is swept when "music" is newly enabled (no video_root equivalent — see musicbay.md §2.1). 41 new tests (musicbrainz.py against a mocked transport, admin-op policy for both new settings, media_cache round-trip/pruning, enrich_audio end-to-end against real ffmpeg-generated MP3s). Full suite (common + node + hub): 1116 passed, no regressions. Client-side (music-app.js, persistent player bar) not started yet. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01KBi7ALLGfwcjBXt57yNMcy --- packages/meshbay-node/src/meshbay_node/roster.py | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'packages/meshbay-node/src/meshbay_node/roster.py') diff --git a/packages/meshbay-node/src/meshbay_node/roster.py b/packages/meshbay-node/src/meshbay_node/roster.py index b4efb7c..24424ab 100644 --- a/packages/meshbay-node/src/meshbay_node/roster.py +++ b/packages/meshbay-node/src/meshbay_node/roster.py @@ -665,6 +665,39 @@ class Roster: await self.set_setting(group_id, self.SETTING_TMDB_ENABLED, "1" if enabled else "0", set_by) + # The Music app's MusicBrainz contact string (docs/musicbay.md §3.2) — + # node-wide, under the same group_id="" sentinel as the TMDB token/ + # language above, for the identical reason: one operator's User-Agent + # identity, not a per-group concern. Unlike TMDB there is no secret to + # store — this is the contact MusicBrainz's usage policy asks a client + # to identify itself with, not a credential. Unset means "no contact + # configured", which musicbrainz.py treats as "make no calls at all" + # (docs/musicbay.md §3.1) rather than sending an unidentified client. + SETTING_MUSICBRAINZ_CONTACT = "musicbrainz_contact" + + async def musicbrainz_contact(self) -> str | None: + return await self.get_setting( + self.NODE_WIDE_GROUP_ID, self.SETTING_MUSICBRAINZ_CONTACT) or None + + async def set_musicbrainz_contact(self, contact: str | None = None, set_by: str = "") -> None: + """`contact=""` clears it; `contact=None` leaves it unchanged (tmdb_config's shape).""" + if contact is not None: + await self.set_setting(self.NODE_WIDE_GROUP_ID, self.SETTING_MUSICBRAINZ_CONTACT, + contact, set_by) + + # Whether MusicBrainz lookups run for this group at all — per-group from + # the start (unlike tmdb_enabled, which started node-wide and moved + # per-group later once the lesson was already learned). Unset means on, + # same "absent means the old behaviour" discipline as everything else. + SETTING_MUSICBRAINZ_ENABLED = "musicbrainz_enabled" + + async def musicbrainz_enabled(self, group_id: str) -> bool: + return (await self.get_setting(group_id, self.SETTING_MUSICBRAINZ_ENABLED, "1")) != "0" + + async def set_musicbrainz_enabled(self, group_id: str, enabled: bool, set_by: str = "") -> None: + await self.set_setting(group_id, self.SETTING_MUSICBRAINZ_ENABLED, + "1" if enabled else "0", set_by) + # How often the indexer's reconciliation backstop runs, and how long it # waits after the last change on a file before hashing it. Unset means # the indexer's own defaults — an existing group's behaviour must not -- cgit v1.2.3