This commit is contained in:
1 parent
0560079b16
commit
db00e57ef7
9 files changed
+328
-228
No files matched your search
@@ -22,6 +22,13 @@ class ZidooError(RuntimeError):
|
||||
|
||||
|
||||
class ZidooClient:
|
||||
# The video player answers getPlayStatus and seekTo, but has no route of
|
||||
# its own for starting or stopping what it is showing -- the box's remote
|
||||
# takes that, and its media keys reach the player like a press on the
|
||||
# handset would. One key per state rather than a single toggle, for the
|
||||
# same reason a room sends the state it wants (see controller.py).
|
||||
KEYS = {"play": "Key.MediaPlay", "pause": "Key.MediaPause"}
|
||||
|
||||
def __init__(self, host, port=9529, timeout=1.5):
|
||||
self.base_url = f"http://{host}:{port}"
|
||||
self.timeout = timeout
|
||||
@@ -70,6 +77,19 @@ class ZidooClient:
|
||||
track["duration_ms"] = video["duration"]
|
||||
return track
|
||||
|
||||
def play_state(self, state):
|
||||
"""Start or stop the loaded video. Like seek(), this is something
|
||||
someone asked for, so a Zidoo that does not answer is an error rather
|
||||
than nothing to show. The key press is acknowledged at once but the
|
||||
player takes a moment to act on it, so the next now_playing() can
|
||||
still report the state it is on its way out of."""
|
||||
key = self.KEYS.get(state)
|
||||
if key is None:
|
||||
raise ZidooError(f"The Zidoo has no key for '{state}' -- only play and pause")
|
||||
payload = self._get_json("ZidooControlCenter/RemoteControl/sendkey", key=key)
|
||||
if not payload or payload.get("status") != 200:
|
||||
raise ZidooError(f"The Zidoo did not {state} -- is it on and reachable?")
|
||||
|
||||
def seek(self, position_ms):
|
||||
"""Jump the loaded video to position_ms. Unlike now_playing(), this
|
||||
is something someone asked for, so a Zidoo that does not answer is
|
||||
|
||||
Reference in new issue
Block a user