sodface wrote: 
> How are you checking for song changes, or did I miss that?  Are you
> polling for changes every few seconds?

Updated version
- event-driven and caches screens
- needs 'sexpect' (https://github.com/clarkwang/sexpect/) and netcat (I
use netcat6 (nc6), others should work as well)
- adjust the player MAC in the curl and in the two sexpect lines (the
XXes)


Code:
--------------------
    
  #!/bin/bash
  
  CACHEDIR=/dev/shm
  
  function sighandler {
        sexpect -sock $SEXPECT_SOCKFILE c
        sexpect -sock $SEXPECT_SOCKFILE w > /dev/null
        exit 0
  }
  
  function get_catt {
        echo $CURR|jq .$1|sed -e "s#'#ยด#g"|sed -e 's#"\(.*\)"#\1#g'
  }
  
  export SEXPECT_SOCKFILE=/tmp/sx-lms.sock
  trap "sighandler" 2
  sexpect sp bash -c 'echo "XX%3AXX%3AXX%3AXX%3AXX%3AXX subscribe playlist 
newsong"|nc6 raspi3-64 9090'
  [[ $? -ne 0 ]] && { echo "sexpect error"; sighandler; }
  
  echo "0" > $CACHEDIR/TID-CURR.txt
  
  while true; do
        [[ "$(<$CACHEDIR/TID-CURR.txt)" -eq "0" ]] || sexpect x -re ".*XX 
playlist newsong.*" > /dev/null
        STATUS=$(curl -s -H "Content-Type: application/json" -X POST -d 
'{"id":1,"method":"slim.request","params":["XX:XX:XX:XX:XX:XX", 
["status",0,999,"tags:acgltys"]]}' "http://raspi3-64:9000/jsonrpc.js";)
        CI=$(echo ${STATUS}|jq '.result.playlist_cur_index | tonumber') 
        CURR=$(echo ${STATUS}|jq ".result.playlist_loop[$CI]")
        CTID=$(get_catt id)
        [[ -z "$CTID" || "$(<$CACHEDIR/TID-CURR.txt)" -eq "$CTID" ]] && continue
        if [ ! -f $CACHEDIR/screen.$CTID.png ]; then
                CAID=$(get_catt artist_id)
                [ -f $CACHEDIR/artist.$CAID.png ] || curl -s -o 
$CACHEDIR/artist.$CAID.png 
"http://raspi3-64:9000/imageproxy/mai/artist/$CAID/image_300x300_m";
        
                curl -s -o - 
"http://raspi3-64:9000/music/current/cover_850x850_o";|convert -resize "x850" 
-antialias -background grey15 -stroke grey50 -fill white  -font Dosis-Medium 
-pointsize 48 -gravity SouthEast -extent 1600x1040 -gravity NorthWest -draw 
"text 10,10 '$(get_catt tracknum). $(get_catt title) ($(get_catt year))' text 
10,80 '$(get_catt album)' text 10,150 '$(get_catt artist)'" -draw "image over 
0,740 0,0 '$CACHEDIR/artist.$CAID.png'"  - "$CACHEDIR/screen.$CTID.png"
        fi
        echo "$CTID" > $CACHEDIR/TID-CURR.txt
        display "$CACHEDIR/screen.$CTID.png" &
  done
  
  
--------------------



SW: 'Web UI for LMS'
(http://forums.slimdevices.com/showthread.php?98186-Announce-Alternative-Web-Interface-(beta))
| 'Playlist Editor / Generator'
(http://forums.slimdevices.com/showthread.php?108199-Announce-LMS-Playlist-Editor)
| 'Music Classification'
(http://forums.slimdevices.com/showthread.php?108278-Announce-Essentia-Integration-music-classification-(moods-genres-))
| 'Similar Music'
(http://forums.slimdevices.com/showthread.php?108495-Announce-LMSmusly-play-similar-music)
| 'LMSlib2go' (https://www.nexus0.net/pub/sw/lmslib2go/)
HowTos: 'build a self-contained LMS'
(http://forums.slimdevices.com/showthread.php?99648-Howto-build-a-self-contained-LMS)
| 'Ogg Opus'
(http://forums.slimdevices.com/showthread.php?107011-Howto-play-Ogg-Opus-files)
| 'Bluetooth/ALSA'
(http://forums.slimdevices.com/showthread.php?107230-Howto-Bluetooth-streaming-to-from-LMS-(ALSA-only-no-PulseAudio))
------------------------------------------------------------------------
Roland0's Profile: http://forums.slimdevices.com/member.php?userid=56808
View this thread: http://forums.slimdevices.com/showthread.php?t=109694

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

Reply via email to