diff options
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/musicbrainz.py')
| -rw-r--r-- | packages/meshbay-node/src/meshbay_node/musicbrainz.py | 33 |
1 files changed, 7 insertions, 26 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/musicbrainz.py b/packages/meshbay-node/src/meshbay_node/musicbrainz.py index 6ca1cf4..59f3778 100644 --- a/packages/meshbay-node/src/meshbay_node/musicbrainz.py +++ b/packages/meshbay-node/src/meshbay_node/musicbrainz.py @@ -17,40 +17,25 @@ account, only: enforced by convention (and by MusicBrainz throttling abusive clients), not a token bucket handed out by the server. -Contact resolution order (docs/musicbay.md §3.2), same shape as tmdb.py's -token resolution: - - 1. an operator-supplied contact string (roster.py group_settings, - group_id="") - 2. the MESHBAY_MUSICBRAINZ_CONTACT_DEFAULT environment variable - 3. none — MusicBrainz lookups are inert (callers get an empty result, - never an exception). Deliberately **not** falling back to a generic - User-Agent: sending an unidentified client to a service that polices - its User-Agent policy risks the node's IP being blocked, which is a - worse failure than "no music metadata yet". - -No literal contact value lives in this file, for the same reason tmdb.py -carries no literal token — see docs/musicbay.md §3.2 on why a personal -address must never land in source control. +Contact resolution: the node owner's hub account email, fetched once at +login via ``GET /v1/users/me`` and passed to this client at construction. +If the owner has no email on file, lookups are inert (callers get an +empty result, never an exception). """ import asyncio import difflib import logging -import os import re import time import httpx -from meshbay_node.roster import Roster - log = logging.getLogger(__name__) _BASE_URL = "https://musicbrainz.org/ws/2/" _COVER_ART_BASE = "https://coverartarchive.org/release/" _TIMEOUT = 10.0 -_DEFAULT_CONTACT_ENV = "MESHBAY_MUSICBRAINZ_CONTACT_DEFAULT" _APP_NAME = "MeshBay-Node" # MusicBrainz's own stated courtesy limit for unauthenticated use. Enforced @@ -112,9 +97,9 @@ def _best_match_release(artist: str, album: str, results: list[dict]) -> tuple[d class MusicBrainzClient: """One instance per node, holding the resolved contact and an httpx client.""" - def __init__(self, roster: Roster | None = None, + def __init__(self, owner_email: str = "", transport: httpx.AsyncBaseTransport | None = None): - self._roster = roster + self._owner_email = owner_email # `transport` is a test-only seam (httpx.MockTransport) — production # callers never pass it. self._client = httpx.AsyncClient(timeout=_TIMEOUT, transport=transport) @@ -125,11 +110,7 @@ class MusicBrainzClient: await self._client.aclose() async def _resolve_contact(self) -> str | None: - if self._roster is not None: - contact = await self._roster.musicbrainz_contact() - else: - contact = None - return contact or os.environ.get(_DEFAULT_CONTACT_ENV) or None + return self._owner_email or None async def _pace(self) -> None: """Serializes every call through this client to >= _MIN_INTERVAL_SECS apart.""" |