summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-common
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-08-24 17:12:36 +0200
committerChristophe Besson <cbesson@gmail.com>2026-08-24 17:12:36 +0200
commit941d1a135dd7b03834576855e8e9fdaa24c4e406 (patch)
tree5d7c27d45a3f1e77320e089f6a4522b8383cbd45 /packages/meshbay-common
parent16bc07acf053d7d14f8182f5523da1d179154a15 (diff)
downloadmeshbay-941d1a135dd7b03834576855e8e9fdaa24c4e406.tar.gz
feat(node): Music app node-side — indexing, MusicBrainz enrichment, protocol
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KBi7ALLGfwcjBXt57yNMcy
Diffstat (limited to 'packages/meshbay-common')
-rw-r--r--packages/meshbay-common/src/meshbay_common/__init__.py9
-rw-r--r--packages/meshbay-common/src/meshbay_common/adminop.py9
-rw-r--r--packages/meshbay-common/src/meshbay_common/protocol.py13
3 files changed, 30 insertions, 1 deletions
diff --git a/packages/meshbay-common/src/meshbay_common/__init__.py b/packages/meshbay-common/src/meshbay_common/__init__.py
index 53c1058..3ed1ed2 100644
--- a/packages/meshbay-common/src/meshbay_common/__init__.py
+++ b/packages/meshbay-common/src/meshbay_common/__init__.py
@@ -24,5 +24,12 @@ __version__ = "0.7.0"
# for one, not all of them). `tmdb_config`/`tmdb_config_ack` keep their name
# but now only cover the token/language, which stay node-wide. Additive: an
# older client simply never sends/handles the new pair.
-MNP_VERSION = "0.7"
+# 0.8: added `artist`/`album`/`track_no` to `IndexEntry`, and
+# `musicbrainz_config`/`_ack`, `musicbrainz_enabled`/`_ack`,
+# `music_meta_req`/`_resp`, for the Music group app (docs/musicbay.md).
+# Same shape as 0.5-0.7's Videos additions, and reuses `duration`/
+# `thumb_hash`/`display_title` rather than declaring new ones. Additive:
+# an older client simply doesn't render the new fields or send the new
+# messages.
+MNP_VERSION = "0.8"
MHP_VERSION = "0.1"
diff --git a/packages/meshbay-common/src/meshbay_common/adminop.py b/packages/meshbay-common/src/meshbay_common/adminop.py
index df806a9..f0a79fe 100644
--- a/packages/meshbay-common/src/meshbay_common/adminop.py
+++ b/packages/meshbay-common/src/meshbay_common/adminop.py
@@ -83,6 +83,15 @@ OP_VIDEO_ROOT = "video_root"
# (media_cache is shared, not per-viewer), so an unsigned override would let
# any member vandalize another show's metadata.
OP_TMDB_OVERRIDE = "tmdb_override"
+# Music app (docs/musicbay.md §6) — same shape as OP_TMDB_CONFIG, minus a
+# secret: MusicBrainz needs no API key, only a rate-limited, self-identifying
+# client, so this only ever carries the User-Agent contact string, node-wide.
+OP_MUSICBRAINZ_CONFIG = "musicbrainz_config"
+# Whether the node calls MusicBrainz *at all* for this group — per-group from
+# the start (unlike TMDB, which started node-wide and was split later once
+# the lesson was already learned once). Signed for the same reason as
+# tmdb_enabled.
+OP_MUSICBRAINZ_ENABLED = "musicbrainz_enabled"
OP_ROOT_ADD = "root_add"
OP_ROOT_REMOVE = "root_remove"
OP_GROUP_ATTACH = "group_attach"
diff --git a/packages/meshbay-common/src/meshbay_common/protocol.py b/packages/meshbay-common/src/meshbay_common/protocol.py
index 32dc373..3b5d428 100644
--- a/packages/meshbay-common/src/meshbay_common/protocol.py
+++ b/packages/meshbay-common/src/meshbay_common/protocol.py
@@ -104,6 +104,15 @@ class MNP:
TMDB_SEARCH_RESP = "tmdb_search_resp" # node → client: candidate list (id, title, year, poster)
TMDB_OVERRIDE = "tmdb_override" # operator → node: replace a show/movie's TMDB match
TMDB_OVERRIDE_ACK = "tmdb_override_ack"
+ # Music app (docs/musicbay.md) — same shape as the TMDB pair above, minus
+ # a credential: MusicBrainz read lookups need no API key, only a
+ # rate-limited, self-identifying client (§3 there).
+ MUSICBRAINZ_CONFIG = "musicbrainz_config" # operator → node: contact string
+ MUSICBRAINZ_CONFIG_ACK = "musicbrainz_config_ack" # node → everyone: new config (no secret)
+ MUSICBRAINZ_ENABLED = "musicbrainz_enabled" # operator → node: enable/disable
+ MUSICBRAINZ_ENABLED_ACK = "musicbrainz_enabled_ack" # node → this group: new enabled state
+ MUSIC_META_REQ = "music_meta_req" # client → node: metadata for a path
+ MUSIC_META_RESP = "music_meta_resp" # node → client: metadata (or none)
# Device linking. A new device files a request bound to a code it displays;
# an already-pinned device of the same account approves it. Neither the hub
# nor the node can produce the countersignature.
@@ -160,6 +169,9 @@ class IndexEntry:
display_title: str | None = None # parsed or cleaned-filename title, Videos app
season: int | None = None # parsed season number, Videos app
episode: int | None = None # parsed episode number, Videos app
+ artist: str | None = None # tag or parsed, Music app
+ album: str | None = None # tag or parsed, Music app
+ track_no: int | None = None # tag or parsed, Music app
def index_entry_wire(e: IndexEntry) -> dict:
@@ -178,6 +190,7 @@ def index_entry_wire(e: IndexEntry) -> dict:
"width": e.width, "height": e.height,
"display_title": e.display_title,
"season": e.season, "episode": e.episode,
+ "artist": e.artist, "album": e.album, "track_no": e.track_no,
}