Support multivalued tags for MusicBrainz IDs too

This commit is contained in:
Danielle McLean 2024-07-23 10:43:22 +10:00
parent 86761bc420
commit 1e6dffcdcc
Signed by: 00dani
GPG key ID: 6854781A0488421C
2 changed files with 21 additions and 17 deletions

View file

@ -1,5 +1,6 @@
from typing import Literal, NotRequired, Protocol, TypedDict
from ..song.musicbrainz import MusicBrainzTags
from ..tools.types import MaybePlural
@ -15,7 +16,7 @@ OneshotFlag = Literal[BooleanFlag, "oneshot"]
# This is not the complete status response from MPD, just the parts of it mpd-now-playable uses.
class StatusResponse(TypedDict):
class StatusResponse(TypedDict, MusicBrainzTags):
state: Literal["play", "stop", "pause"]
# The total duration and elapsed playback of the current song, measured in seconds. Fractional seconds are allowed.
@ -48,7 +49,7 @@ class StatusResponse(TypedDict):
# optional. mpd-now-playable will work better if your music is properly
# tagged, since then it can pass more information on to Now Playing, but it
# should work fine with completely untagged music too.
class CurrentSongTags(TypedDict, total=False):
class CurrentSongTags(TypedDict, MusicBrainzTags, total=False):
artist: MaybePlural[str]
albumartist: MaybePlural[str]
artistsort: MaybePlural[str]
@ -62,11 +63,6 @@ class CurrentSongTags(TypedDict, total=False):
disc: str
label: str
genre: MaybePlural[str]
musicbrainz_albumid: str
musicbrainz_albumartistid: str
musicbrainz_releasetrackid: str
musicbrainz_artistid: str
musicbrainz_trackid: str
class CurrentSongResponse(CurrentSongTags):

View file

@ -5,12 +5,16 @@ from uuid import UUID
from pydantic import Field
from ..tools.types import option_fmap
from ..tools.types import MaybePlural, option_fmap, un_maybe_plural
option_uuid = partial(option_fmap, UUID)
OptionUUID = Annotated[UUID | None, Field(default=None)]
def to_uuids(values: MaybePlural[str] | None) -> list[UUID]:
return [UUID(i) for i in un_maybe_plural(values)]
class MusicBrainzTags(TypedDict, total=False):
"""
The MusicBrainz tags mpd-now-playable expects and will load (all optional).
@ -24,11 +28,11 @@ class MusicBrainzTags(TypedDict, total=False):
#: MusicBrainz Track ID
musicbrainz_releasetrackid: str
#: MusicBrainz Artist ID
musicbrainz_artistid: str
musicbrainz_artistid: MaybePlural[str]
#: MusicBrainz Release ID
musicbrainz_albumid: str
musicbrainz_albumid: MaybePlural[str]
#: MusicBrainz Release Artist ID
musicbrainz_albumartistid: str
musicbrainz_albumartistid: MaybePlural[str]
#: MusicBrainz Release Group ID
musicbrainz_releasegroupid: str
#: MusicBrainz Work ID
@ -63,19 +67,23 @@ class MusicBrainzIds:
#: https://musicbrainz.org/doc/Track
track: OptionUUID
#: A MusicBrainz artist is pretty intuitively the artist who recorded the
#: song. This particular ID refers to the individual recording's artist or
#: artists, which may be distinct from the release artist below when a
#: release contains recordings from many different artists.
#: https://musicbrainz.org/doc/Artist
artist: OptionUUID
artist: list[UUID]
#: A MusicBrainz release roughly corresponds to an "album", and indeed is
#: stored in a tag called MUSICBRAINZ_ALBUMID. The more general name is
#: meant to encompass all the different ways music can be released.
#: https://musicbrainz.org/doc/Release
release: OptionUUID
release: list[UUID]
#: Again, the release artist corresponds to an "album artist". These MBIDs
#: refer to the same artists in the MusicBrainz database that individual
#: recordings' artist MBIDs do.
release_artist: OptionUUID
release_artist: list[UUID]
#: A MusicBrainz release group roughly corresponds to "all the editions of
#: a particular album". For example, if the same album were released on CD,
@ -92,8 +100,8 @@ def to_brainz(tags: MusicBrainzTags) -> MusicBrainzIds:
recording=option_uuid(tags.get("musicbrainz_trackid")),
work=option_uuid(tags.get("musicbrainz_workid")),
track=option_uuid(tags.get("musicbrainz_releasetrackid")),
artist=option_uuid(tags.get("musicbrainz_artistid")),
release=option_uuid(tags.get("musicbrainz_albumid")),
release_artist=option_uuid(tags.get("musicbrainz_albumartistid")),
artist=to_uuids(tags.get("musicbrainz_artistid")),
release=to_uuids(tags.get("musicbrainz_albumid")),
release_artist=to_uuids(tags.get("musicbrainz_albumartistid")),
release_group=option_uuid(tags.get("musicbrainz_releasegroupid")),
)