Re: LMS-CLI: telnet - "playlist index +1" does not work
thinkalready <thinkalready.a82xun-NUepA2SMhDQqspMVqqL2D+4xXEVPTSb/[email protected]>
| Newsgroups | gmane.music.equipment.slimdevices.devel |
|---|---|
| Organization | Logitech Squeezebox Forums |
| Message-ID | <[email protected]> |
To whomever is interested in my fix:
In order to use the linked radio stations straight out of Squeezebox
(m3u playlists), I instead changed my code from relative indexing (+1,
-1) to absolute indexing.
Code:
--------------------
import lirc
import time
import telnetlib
import RPi.GPIO as GPIO
sockid = lirc.init("monitor", config_filename="~/App/SqueezeIRControl/monitor.lircrc", blocking=False)
while True:
try:
telnetid = telnetlib.Telnet("localhost", 9090)
break
except:
print "telnet connection error: try again ..."
playpause = False
relaypin = 5
#GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(relaypin, GPIO.OUT)
GPIO.output(relaypin, GPIO.LOW)
playidx = 0
playcount = 0
while True:
codeIR = lirc.nextcode()
if codeIR != []:
if codeIR[0] == "KEY_DOWN":
print "mixer volume -5"
telnetid.write("mixer volume -5 \r")
tmp = telnetid.read_until("mixer volume -5")
print tmp
elif codeIR[0] == "KEY_LEFT":
#print "playlist index -1"
#telnetid.write("playlist index -1 \r")
telnetid.write("playlist tracks ? \r")
telnetid.read_until("playlist tracks ")
playcount = int(telnetid.read_some())
playidx -= 1
if playidx<0:
playidx = playcount - 1
elif playidx>=playcount:
playidx = 0
telnetid.write("playlist index " + str(playidx) + " \r");
telnetid.read_until("playlist index");
playtmp = int (telnetid.read_some())
print "playlist index " + str(playtmp) + " (" + str(playtmp+1) + "/" + str(playcount) + ")"
elif codeIR[0] == "KEY_RIGHT":
#print "playlist index +1"
#telnetid.write("playlist index %2B1 \r")
telnetid.write("playlist tracks ? \r")
telnetid.read_until("playlist tracks ")
playcount = int(telnetid.read_some())
playidx += 1
if playidx>=playcount:
playidx = 0
telnetid.write("playlist index " + str(playidx) + " \r");
telnetid.read_until("playlist index");
playtmp = int (telnetid.read_some())
print "playlist index " + str(playtmp) + " (" + str(playtmp+1) + "/" + str(playcount) + ")"
elif codeIR[0] == "KEY_UP":
print "mixer volume +5"
telnetid.write("mixer volume +5 \r")
tmp = telnetid.read_until("mixer volume")
print tmp
elif codeIR[0] == "KEY_MENU":
print "stop"
telnetid.write("stop\r")
tmp = telnetid.read_until("stop")
print tmp
GPIO.output(relaypin, GPIO.LOW)
playpause = False
elif codeIR[0] == "KEY_PLAYPAUSE":
if playpause==True:
print "pause"
telnetid.write("pause\r")
tmp = telnetid.read_until("pause")
print tmp
playpause = False
else:
print "play"
GPIO.output(relaypin, GPIO.HIGH)
telnetid.write("play\r")
tmp = telnetid.read_until("play")
print tmp
playpause = True
else:
print codeIR
# else: # codeIR == []
# print "nothing to do"
time.sleep(0.05)
GPIO.cleanup()
--------------------
------------------------------------------------------------------------
thinkalready's Profile: http://forums.slimdevices.com/member.php?userid=72028
View this thread: http://forums.slimdevices.com/showthread.php?t=115006