From c4dd27ad959c533d821677d25005f3b563884d4c Mon Sep 17 00:00:00 2001 From: fatherflump Date: Tue, 21 Apr 2026 15:27:12 +0100 Subject: [PATCH] Allow for playback duration to be missing In the UK, Netflix and NOW TV seem to miss this information out. --- roku/_async/core.py | 6 +++++- roku/core.py | 6 +++++- roku/models.py | 6 +++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/roku/_async/core.py b/roku/_async/core.py index 729f03c..3dc376d 100644 --- a/roku/_async/core.py +++ b/roku/_async/core.py @@ -157,11 +157,15 @@ async def get_media_player(self): roku=self, ) + # Duration isn't provided by all apps in all cases, e.g. Netflix / NOW TV + duration_element = root.find("duration") + duration = int(duration_element.text.split(" ", 1)[0]) if duration_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]), + duration=duration, ) return mp diff --git a/roku/core.py b/roku/core.py index fe0e9c8..8838059 100644 --- a/roku/core.py +++ b/roku/core.py @@ -162,11 +162,15 @@ 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 / NOW TV + duration_element = root.find("duration") + duration = int(duration_element.text.split(" ", 1)[0]) if duration_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]), + duration=duration, ) return mp diff --git a/roku/models.py b/roku/models.py index e9a69df..e32b897 100644 --- a/roku/models.py +++ b/roku/models.py @@ -94,9 +94,9 @@ def __init__(self, state, app, position, duration): self.duration = duration def __repr__(self): - return "" % ( + progress = f("%s/%s", self.position, self.duration) if self.duration is not None else f("%s", self.position) + return "" % ( self.state, self.app.name, - self.position, - self.duration, + progress, )