Support multivalued song tags (fixes #1)

python-mpd2 unreliably returns either a single value or a list of
values for commands like currentsong, which is super fun if you're
trying to write type stubs for it that statically describe its
behaviour. Whee.

Anyway, I ended up changing my internal song model to always use lists
for tags like artist and genre which are likely to have multiple values.
There's some finagling involved in massaging python-mpd2's output into
lists every time. However it's much nicer to work with an object that
always has a list of artists, even if it's a list of one or zero
artists, rather than an object that can have a single artist, a list of
multiple artists, or a null. So it's worth it.

The MPNowPlayingInfoCenter in MacOS only works with single string values
for these tags, not lists, so we have to join the artists and such into
a single string for its consumption. I'm using commas for the separator
at the moment, but I may make this a config option later on if there's
interest.
This commit is contained in:
Danielle McLean 2024-06-23 17:24:37 +10:00
parent 2f70c6f7fa
commit bc56686fc4
Signed by: 00dani
GPG key ID: 6854781A0488421C
6 changed files with 81 additions and 31 deletions

View file

@ -21,18 +21,17 @@ class Song:
musicbrainz_trackid: UUID | None
musicbrainz_releasetrackid: UUID | None
title: str | None
artist: str | None
composer: str | None
album: str | None
album_artist: str | None
artist: list[str]
composer: list[str]
album: list[str]
album_artist: list[str]
track: int | None
disc: int | None
genre: str | None
genre: list[str]
duration: float
elapsed: float
art: bytes | None = field(repr=lambda a: "<has art>" if a else "<no art>")
class SongListener(Protocol):
def update(self, song: Song | None) -> None:
...
def update(self, song: Song | None) -> None: ...