From 511e41f214356f90eafa19cc445c424ade7c1d17 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 9 Feb 2015 23:29:58 +0000 Subject: [PATCH] initial commit --- mpdWatch.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 mpdWatch.py diff --git a/mpdWatch.py b/mpdWatch.py new file mode 100644 index 0000000..ec7495b --- /dev/null +++ b/mpdWatch.py @@ -0,0 +1,56 @@ +#!/bin/python3 +import rxv +from mpd import MPDClient +import time + +def main(): + client = MPDClient() + client.connect("localhost", 6600) + receivers = rxv.find() + rx = receivers[0] + lastState = getMPDStatus(client) + while True: + #Check if paused or seeking + if getMPDStatus(client) != lastState: + #play toggled + if getMPDStatus(client) == 1: + #playing now - turn on receiver asap + if not rx.on: + #dirty workaround so that my cubie detects the receiver as output + rx.on = True + time.sleep(4) + rx.input = "HDMI1" + time.sleep(1) + rx.input = "HDMI2" + else: + turnOff = waitForChanges(client, 10) + if turnOff: + #lets not waste energy and turn of the receiver + rx.on = False + + lastState = getMPDStatus(client) + #wait until the player-subsystem gets changed + client.idle("player") + + client.close() + client.disconnect() + +def getMPDStatus( client ): + if "play" in client.status()["state"]: + return 1 + else: + return 0 + +def waitForChanges( client, timeout ): + counter = 0 + initState = getMPDStatus(client) + ranIntoTimeout = True + while counter < timeout: + if getMPDStatus(client) != initState: + ranIntoTimeout = False + break; + time.sleep(0.1) + counter += 1 + return ranIntoTimeout + +main()