Support current songs with no duration, such as streams

This commit is contained in:
Danielle McLean 2024-07-23 13:38:41 +10:00
parent 012bc0b025
commit dbd507bccb
Signed by: 00dani
GPG key ID: 6854781A0488421C
3 changed files with 9 additions and 5 deletions

View file

@ -49,7 +49,7 @@ def mpd_state_to_song(config: MpdConfig, mpd: MpdState) -> Song:
genre=un_maybe_plural(mpd.current.get("genre")),
track=option_fmap(int, mpd.current.get("track")),
disc=option_fmap(int, mpd.current.get("disc")),
duration=float(mpd.status["duration"]),
duration=option_fmap(float, mpd.status.get("duration")),
elapsed=float(mpd.status["elapsed"]),
musicbrainz=to_brainz(mpd.current),
art=to_artwork(mpd.art),

View file

@ -20,8 +20,11 @@ OneshotFlag = Literal[BooleanFlag, "oneshot"]
class StatusResponse(TypedDict):
state: Literal["play", "stop", "pause"]
# The total duration and elapsed playback of the current song, measured in seconds. Fractional seconds are allowed.
duration: str
# The total duration and elapsed playback of the current song, measured in
# seconds. Fractional seconds are allowed. The duration field may be
# omitted because MPD cannot determine the duration of certain sources,
# such as Internet radio streams.
duration: NotRequired[str]
elapsed: str
# The volume value ranges from 0-100. It may be omitted from

View file

@ -69,8 +69,9 @@ class Song:
genre: list[str]
#: The song's duration as read from its tags, measured in seconds.
#: Fractional seconds are allowed.
duration: float
#: Fractional seconds are allowed. The duration may be unavailable for some
#: sources, such as internet radio streams.
duration: float | None
#: How far into the song MPD is, measured in seconds. Fractional seconds
#: are allowed. This is usually going to be less than or equal to the