Thanks to Roland0 and Paul,  I've been testing with sexpect and JSON.awk
and it's working fairly well for detecting a "newsong" event and
retrieving json playlist info.  The operation of sexpect is pretty
confusing.  Seems like there should be a way to clear the buffer after a
match and a way to keep spawned processes from spewing all over stdout
but it's probably operator error.


Code:
--------------------
    
  #!/bin/sh
  sexpect -s 9090.sock spawn telnet 192.168.1.201 9090 &
  sleep .5
  sexpect -s 9090.sock send -enter "b8%3A27%3Aeb%3A94%3Aae%3A63 subscribe 
playlist"
  
  while :
  do
  sexpect -s 9090.sock expect -re "newsong"
  sexpect -s 9090.sock expect -re ".*"
  
  sexpect -s 9000.sock spawn nc 192.168.1.201 9000 &
  sleep .1
  sexpect -s 9000.sock send -f test
  sexpect -s 9000.sock expect -timeout 10 -glob '{"params":*'
  title=$(sexpect -s 9000.sock expect_out -index 0 | awk -f 
/usr/local/bin/JSON.awk - | grep -m 1 '0,"title"' | cut -f2 | cut -d '"' -f2)
  artist=$(sexpect -s 9000.sock expect_out -index 0 | awk -f 
/usr/local/bin/JSON.awk - | grep -m 1 '"artist"' | cut -f2 | cut -d '"' -f2)
  album=$(sexpect -s 9000.sock expect_out -index 0 | awk -f 
/usr/local/bin/JSON.awk - | grep -m 1 '"album"' | cut -f2 | cut -d '"' -f2)
  station=$(sexpect -s 9000.sock expect_out -index 0 | awk -f 
/usr/local/bin/JSON.awk - | grep -m 1 '"remote_title"' | cut -f2 | cut -d '"' 
-f2)
  sexpect -s 9000.sock close
  pid=$(sexpect -s 9000.sock get -ppid)
  kill $pid
  
  echo "$title"
  echo "$artist"
  echo "$album"
  echo "$station"
  done
  
  kill $pid
  pid=$(sexpect -s 9090.sock get -ppid)
  kill $pid
  rm 9090.sock 9000.sock
  
--------------------


------------------------------------------------------------------------
sodface's Profile: http://forums.slimdevices.com/member.php?userid=19057
View this thread: http://forums.slimdevices.com/showthread.php?t=109694

_______________________________________________
unix mailing list
unix@lists.slimdevices.com
http://lists.slimdevices.com/mailman/listinfo/unix

Reply via email to