Hi Jan,

I took the liberty of slightly modifying the script ;-) Just in case I
paused my player it won't be powered off if it starts playing within 2
minutes.
Also won't power it off it it has been powered off before.

Cheers,

Marc



Code:
--------------------
    #!/bin/bash
  ## check if any player is playing
  ## and restart squeezelite if timetoplay is equal on both checks
  
  ##vars
  port=9090
  server=192.168.1.5
  LOGFILE=/tmp/playercheck.log
  
  #to use a fresh logfile use > below for each run
  echo "============================================" > $LOGFILE
  echo "$(date)" >> $LOGFILE
  
  # get number of known players
  players=$(printf "player count ?\nexit\n" | nc ${server} ${port} | cut -d ' ' 
-f 3)
  echo "There are ${players} known players." >> $LOGFILE
  
  ## check all known players
  for((i=0; i<${players}; i++))
  do
  echo "" >> $LOGFILE
  playerID=$(printf "player id $i ?\nexit\n" | nc ${server} ${port} | cut -d ' 
' -f 4 | sed 's/%/%%/g')
  playeron=$(printf "${playerID} power ?\nexit\n" | nc $server $port | cut -d ' 
' -f 3)
  playername=$(printf "$playerID name ?\nexit\n" | nc $server $port | cut -d ' 
' -f 3)
  
  if [ ${playeron} = '0' ]
  then
  echo "Player ${playername} is already powered off." >> $LOGFILE
  else
  playername=$(printf "$playerID name ?\nexit\n" | nc $server $port | cut -d ' 
' -f 3)
  echo "Player nr ${i} is called ${playername}." >> $LOGFILE
  
  timetoplay1=$(printf "$playerID time ?\nexit\n" | nc $server $port | cut -d ' 
' -f 3)
  sleep 1
  timetoplay2=$(printf "$playerID time ?\nexit\n" | nc $server $port | cut -d ' 
' -f 3)
  
  if [ $timetoplay1 = $timetoplay2 ]
  then
  echo "Player $playername is not playing right now. Checking if it is paused 
..." >> $LOGFILE
  sleep 120
  timetoplay3=$(printf "$playerID time ?\nexit\n" | nc $server $port | cut -d ' 
' -f 3)
  if [ $timetoplay1 = $timetoplay3 ]
  then
  echo "Powering off ${playername}." >> $LOGFILE
  printf "$playerID power 0 \nexit\n" | nc $server $port 2>&1>/dev/null
  else
  echo "Player has resumed playing, all good !"
  fi
  else
  echo "Player ${playername} is playing fine." >> $LOGFILE
  fi
  fi
  done
  
--------------------


------------------------------------------------------------------------
mulsoft's Profile: http://forums.slimdevices.com/member.php?userid=62415
View this thread: http://forums.slimdevices.com/showthread.php?t=99916

_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix

Reply via email to