Add duration support for streaming in mpd (#66110)

* Add duration support for streaming in mpd

* Change to use 1 line instead of if

* Improve code to be more readable
This commit is contained in:
yoedf 2022-03-29 11:36:05 +03:00 committed by GitHub
parent d655d54a8f
commit 88780b4c87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -227,8 +227,14 @@ class MpdDevice(MediaPlayerEntity):
@property
def media_duration(self):
"""Return the duration of current playing media in seconds."""
# Time does not exist for streams
return self._currentsong.get("time")
if currentsong_time := self._currentsong.get("time"):
return currentsong_time
time_from_status = self._status.get("time")
if isinstance(time_from_status, str) and ":" in time_from_status:
return time_from_status.split(":")[1]
return None
@property
def media_position(self):