initial commit

This commit is contained in:
root 2015-02-09 23:29:58 +00:00
commit 511e41f214

56
mpdWatch.py Normal file
View file

@ -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()