better code for "previous"

This commit is contained in:
tilman
2016-12-30 06:47:46 +01:00
parent bdf0d139b5
commit 1d8841ceec
+5 -8
View File
@@ -43,14 +43,11 @@ position = 0
def btn1_callback(channel): def btn1_callback(channel):
logging.debug('PREV_CALLBACK') logging.debug('PREV_CALLBACK')
out, err = subprocess.Popen(['mocp','--info'], stdout=subprocess.PIPE).communicate() out, err = subprocess.Popen(['mocp','-Q', '%state'], stdout=subprocess.PIPE).communicate()
info = out.splitlines() if (out.decode("utf-8").startswith('PLAY')):
for s in info: out, err = subprocess.Popen(['mocp','-Q', '%cs'], stdout=subprocess.PIPE).communicate()
s = s.decode("utf-8") position = int(out.decode("utf-8"))
if s.startswith('CurrentSec'): if (position < 4):
position = s[s.rfind(' ')+1:]
logging.debug(int(position))
if (int(position) < 4):
logging.debug('mocp --previous') logging.debug('mocp --previous')
subprocess.call(["mocp", "--previous"]) subprocess.call(["mocp", "--previous"])
else: else: