diff --git a/roku/_async/core.py b/roku/_async/core.py index 729f03c..4ea0fa5 100644 --- a/roku/_async/core.py +++ b/roku/_async/core.py @@ -157,11 +157,18 @@ async def get_media_player(self): roku=self, ) + # Duration isn't provided by all apps in all cases, e.g. Netflix / Amazon Prime Video + duration_element = root.find("duration") + duration = int(duration_element.text.split(" ", 1)[0]) if duration_element is not None else None + # Position can be absent for some states. + position_element = root.find("position") + position = int(position_element.text.split(" ", 1)[0]) if position_element is not None else None + mp = MediaPlayer( state=root.get("state"), app=app, - position=int(root.find("position").text.split(" ", 1)[0]), - duration=int(root.find("duration").text.split(" ", 1)[0]), + position=position, + duration=duration, ) return mp diff --git a/roku/core.py b/roku/core.py index fe0e9c8..df92e9f 100644 --- a/roku/core.py +++ b/roku/core.py @@ -162,11 +162,18 @@ def media_player(self): resp = self._get("/query/media-player") root = ET.fromstring(resp) + # Duration isn't provided by all apps in all cases, e.g. Netflix / Amazon Prime Video + duration_element = root.find("duration") + duration = int(duration_element.text.split(" ", 1)[0]) if duration_element is not None else None + # Position can be absent for some states. + position_element = root.find("position") + position = int(position_element.text.split(" ", 1)[0]) if position_element is not None else None + mp = MediaPlayer( state=root.get("state"), app=self[int(root.find("plugin").get("id"))], - position=int(root.find("position").text.split(" ", 1)[0]), - duration=int(root.find("duration").text.split(" ", 1)[0]), + position=position, + duration=duration, ) return mp diff --git a/roku/models.py b/roku/models.py index e9a69df..2f418bc 100644 --- a/roku/models.py +++ b/roku/models.py @@ -94,9 +94,10 @@ def __init__(self, state, app, position, duration): self.duration = duration def __repr__(self): - return "" % ( + position_str = f("%s", self.position) if self.position is not None else "??" + progress = f("%s/%s", position_str, self.duration) if self.duration is not None else position_str + return "" % ( self.state, self.app.name, - self.position, - self.duration, + progress, )