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/ops.py | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'packages/meshbay-node/src/meshbay_node/ops.py') diff --git a/packages/meshbay-node/src/meshbay_node/ops.py b/packages/meshbay-node/src/meshbay_node/ops.py index a232ba2..d439ec3 100644 --- a/packages/meshbay-node/src/meshbay_node/ops.py +++ b/packages/meshbay-node/src/meshbay_node/ops.py @@ -728,6 +728,14 @@ async def set_enabled_apps(state: dict, group_id: str, apps: list[str]) -> dict: set_by=state.get("node_user_id", "")) ctx["enabled_apps"] = apps log.info("Enabled apps for group %s: %s", group_id[:8], ",".join(sorted(apps))) + if "music" in apps: + # Music has no root of its own to key a sweep off (unlike + # set_video_root's enrich_video_root_fn) — turning the app on at all + # is the trigger, mirroring that same "sweep what's already there" + # need (docs/musicbay.md §2.1, daemon._enrich_music_now). + enrich_fn = state.get("enrich_music_now_fn") + if enrich_fn: + asyncio.ensure_future(enrich_fn(group_id)) return {"apps": apps, "group_id": group_id} @@ -781,6 +789,40 @@ async def set_tmdb_enabled(state: dict, group_id: str, enabled: bool) -> dict: return {"enabled": enabled, "group_id": group_id} +# ── MusicBrainz config (Music app) ─────────────────────────────────────────── + +async def set_musicbrainz_config(state: dict, contact: str | None = None) -> dict: + """ + The node-wide User-Agent contact string MusicBrainz's usage policy asks + for (docs/musicbay.md §3.2). Unlike set_tmdb_config there is no token to + manage — MusicBrainz's read endpoints need no credential — so this is a + single field. `contact=""` explicitly clears a previously-set contact + (reverting to "no calls at all", never a generic/unidentified + User-Agent); `contact=None` leaves whatever was there unchanged. + """ + roster = _roster(state) + await roster.set_musicbrainz_contact(contact, set_by=state.get("node_user_id", "")) + if contact is not None: + state["musicbrainz_contact_configured"] = bool(contact) + log.info("MusicBrainz config: contact_configured=%s", bool(contact)) + return {"contact_configured": state.get("musicbrainz_contact_configured", False)} + + +async def set_musicbrainz_enabled(state: dict, group_id: str, enabled: bool) -> dict: + """ + Whether MusicBrainz lookups run for this group at all + (docs/musicbay.md §6) — per-group from the start, same reasoning as + set_tmdb_enabled: a real media-library group and a test/demo group on + one node need not share the decision to make outbound requests. + """ + roster = _roster(state) + ctx = _group_ctx(state, group_id) + await roster.set_musicbrainz_enabled(group_id, enabled, set_by=state.get("node_user_id", "")) + ctx["musicbrainz_enabled"] = enabled + log.info("MusicBrainz enabled for group %s: %s", group_id[:8], enabled) + return {"enabled": enabled, "group_id": group_id} + + async def set_video_root(state: dict, group_id: str, path: str) -> dict: """ Which folder (possibly a subfolder of a shared root) is the Videos app's -- cgit v1.2.3