better code for "previous"
This commit is contained in:
+10
-13
@@ -43,19 +43,16 @@ position = 0
|
||||
|
||||
def btn1_callback(channel):
|
||||
logging.debug('PREV_CALLBACK')
|
||||
out, err = subprocess.Popen(['mocp','--info'], stdout=subprocess.PIPE).communicate()
|
||||
info = out.splitlines()
|
||||
for s in info:
|
||||
s = s.decode("utf-8")
|
||||
if s.startswith('CurrentSec'):
|
||||
position = s[s.rfind(' ')+1:]
|
||||
logging.debug(int(position))
|
||||
if (int(position) < 4):
|
||||
logging.debug('mocp --previous')
|
||||
subprocess.call(["mocp", "--previous"])
|
||||
else:
|
||||
logging.debug('mocp --jump 0s')
|
||||
subprocess.call(["mocp", "--jump", "0s"])
|
||||
out, err = subprocess.Popen(['mocp','-Q', '%state'], stdout=subprocess.PIPE).communicate()
|
||||
if (out.decode("utf-8").startswith('PLAY')):
|
||||
out, err = subprocess.Popen(['mocp','-Q', '%cs'], stdout=subprocess.PIPE).communicate()
|
||||
position = int(out.decode("utf-8"))
|
||||
if (position < 4):
|
||||
logging.debug('mocp --previous')
|
||||
subprocess.call(["mocp", "--previous"])
|
||||
else:
|
||||
logging.debug('mocp --jump 0s')
|
||||
subprocess.call(["mocp", "--jump", "0s"])
|
||||
|
||||
def btn2_callback(channel):
|
||||
logging.debug('mocp --toggle-pause')
|
||||
|
||||
Reference in New Issue
Block a user