diff --git a/src/mpd_now_playable/mpd/listener.py b/src/mpd_now_playable/mpd/listener.py index 01a1aaf..75852f7 100644 --- a/src/mpd_now_playable/mpd/listener.py +++ b/src/mpd_now_playable/mpd/listener.py @@ -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), diff --git a/src/mpd_now_playable/mpd/types.py b/src/mpd_now_playable/mpd/types.py index 98f6612..8d9db81 100644 --- a/src/mpd_now_playable/mpd/types.py +++ b/src/mpd_now_playable/mpd/types.py @@ -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 diff --git a/src/mpd_now_playable/song/song.py b/src/mpd_now_playable/song/song.py index 3b2bbe1..45c4425 100644 --- a/src/mpd_now_playable/song/song.py +++ b/src/mpd_now_playable/song/song.py @@ -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