Support multivalued tags for MusicBrainz IDs too
This commit is contained in:
parent
86761bc420
commit
1e6dffcdcc
2 changed files with 21 additions and 17 deletions
|
@ -1,5 +1,6 @@
|
||||||
from typing import Literal, NotRequired, Protocol, TypedDict
|
from typing import Literal, NotRequired, Protocol, TypedDict
|
||||||
|
|
||||||
|
from ..song.musicbrainz import MusicBrainzTags
|
||||||
from ..tools.types import MaybePlural
|
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.
|
# 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"]
|
state: Literal["play", "stop", "pause"]
|
||||||
|
|
||||||
# The total duration and elapsed playback of the current song, measured in seconds. Fractional seconds are allowed.
|
# 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
|
# 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
|
# tagged, since then it can pass more information on to Now Playing, but it
|
||||||
# should work fine with completely untagged music too.
|
# should work fine with completely untagged music too.
|
||||||
class CurrentSongTags(TypedDict, total=False):
|
class CurrentSongTags(TypedDict, MusicBrainzTags, total=False):
|
||||||
artist: MaybePlural[str]
|
artist: MaybePlural[str]
|
||||||
albumartist: MaybePlural[str]
|
albumartist: MaybePlural[str]
|
||||||
artistsort: MaybePlural[str]
|
artistsort: MaybePlural[str]
|
||||||
|
@ -62,11 +63,6 @@ class CurrentSongTags(TypedDict, total=False):
|
||||||
disc: str
|
disc: str
|
||||||
label: str
|
label: str
|
||||||
genre: MaybePlural[str]
|
genre: MaybePlural[str]
|
||||||
musicbrainz_albumid: str
|
|
||||||
musicbrainz_albumartistid: str
|
|
||||||
musicbrainz_releasetrackid: str
|
|
||||||
musicbrainz_artistid: str
|
|
||||||
musicbrainz_trackid: str
|
|
||||||
|
|
||||||
|
|
||||||
class CurrentSongResponse(CurrentSongTags):
|
class CurrentSongResponse(CurrentSongTags):
|
||||||
|
|
|
@ -5,12 +5,16 @@ from uuid import UUID
|
||||||
|
|
||||||
from pydantic import Field
|
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)
|
option_uuid = partial(option_fmap, UUID)
|
||||||
OptionUUID = Annotated[UUID | None, Field(default=None)]
|
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):
|
class MusicBrainzTags(TypedDict, total=False):
|
||||||
"""
|
"""
|
||||||
The MusicBrainz tags mpd-now-playable expects and will load (all optional).
|
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 Track ID
|
||||||
musicbrainz_releasetrackid: str
|
musicbrainz_releasetrackid: str
|
||||||
#: MusicBrainz Artist ID
|
#: MusicBrainz Artist ID
|
||||||
musicbrainz_artistid: str
|
musicbrainz_artistid: MaybePlural[str]
|
||||||
#: MusicBrainz Release ID
|
#: MusicBrainz Release ID
|
||||||
musicbrainz_albumid: str
|
musicbrainz_albumid: MaybePlural[str]
|
||||||
#: MusicBrainz Release Artist ID
|
#: MusicBrainz Release Artist ID
|
||||||
musicbrainz_albumartistid: str
|
musicbrainz_albumartistid: MaybePlural[str]
|
||||||
#: MusicBrainz Release Group ID
|
#: MusicBrainz Release Group ID
|
||||||
musicbrainz_releasegroupid: str
|
musicbrainz_releasegroupid: str
|
||||||
#: MusicBrainz Work ID
|
#: MusicBrainz Work ID
|
||||||
|
@ -63,19 +67,23 @@ class MusicBrainzIds:
|
||||||
#: https://musicbrainz.org/doc/Track
|
#: https://musicbrainz.org/doc/Track
|
||||||
track: OptionUUID
|
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
|
#: https://musicbrainz.org/doc/Artist
|
||||||
artist: OptionUUID
|
artist: list[UUID]
|
||||||
|
|
||||||
#: A MusicBrainz release roughly corresponds to an "album", and indeed is
|
#: A MusicBrainz release roughly corresponds to an "album", and indeed is
|
||||||
#: stored in a tag called MUSICBRAINZ_ALBUMID. The more general name is
|
#: stored in a tag called MUSICBRAINZ_ALBUMID. The more general name is
|
||||||
#: meant to encompass all the different ways music can be released.
|
#: meant to encompass all the different ways music can be released.
|
||||||
#: https://musicbrainz.org/doc/Release
|
#: https://musicbrainz.org/doc/Release
|
||||||
release: OptionUUID
|
release: list[UUID]
|
||||||
|
|
||||||
#: Again, the release artist corresponds to an "album artist". These MBIDs
|
#: Again, the release artist corresponds to an "album artist". These MBIDs
|
||||||
#: refer to the same artists in the MusicBrainz database that individual
|
#: refer to the same artists in the MusicBrainz database that individual
|
||||||
#: recordings' artist MBIDs do.
|
#: recordings' artist MBIDs do.
|
||||||
release_artist: OptionUUID
|
release_artist: list[UUID]
|
||||||
|
|
||||||
#: A MusicBrainz release group roughly corresponds to "all the editions of
|
#: A MusicBrainz release group roughly corresponds to "all the editions of
|
||||||
#: a particular album". For example, if the same album were released on CD,
|
#: 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")),
|
recording=option_uuid(tags.get("musicbrainz_trackid")),
|
||||||
work=option_uuid(tags.get("musicbrainz_workid")),
|
work=option_uuid(tags.get("musicbrainz_workid")),
|
||||||
track=option_uuid(tags.get("musicbrainz_releasetrackid")),
|
track=option_uuid(tags.get("musicbrainz_releasetrackid")),
|
||||||
artist=option_uuid(tags.get("musicbrainz_artistid")),
|
artist=to_uuids(tags.get("musicbrainz_artistid")),
|
||||||
release=option_uuid(tags.get("musicbrainz_albumid")),
|
release=to_uuids(tags.get("musicbrainz_albumid")),
|
||||||
release_artist=option_uuid(tags.get("musicbrainz_albumartistid")),
|
release_artist=to_uuids(tags.get("musicbrainz_albumartistid")),
|
||||||
release_group=option_uuid(tags.get("musicbrainz_releasegroupid")),
|
release_group=option_uuid(tags.get("musicbrainz_releasegroupid")),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue