#!/usr/local/bin/ksh ################################################################################# # Script sc (slimcommander) # # Description Sends commands to the SlimServer MP3 player. # # Modifications 06/26/04 - $progname added to temp files for tracking. - rmorten# # 07/01/05 - Added error handling and comments. Also added the # # ability to call playlists with their common names instead of # # only by a number. Organized playlists. - rmorten # # Written On 06/30/05 # # Written By Rick Mortensen # ################################################################################# # Directory Variables MP3=/usr/home/etc/mp3 # Program Variables progname=sc nc=/usr/local/bin/nc bkdate=/bin/bkdate awk=/usr/bin/awk nawk=/usr/local/bin/nawk htod=/home/bin/htod dtoh=/home/bin/dtoh DAYMINUS30=`$bkdate -d30 '+%y%m%d'` YESTERDATE=`$bkdate -d1 '+%m/%d'` YESTERDAY=`$bkdate -d1 '+%y%m%d'` DATE=`date '+%m/%d'` DAY=`date '+%y%m%d'` SERIAL=`date '+%y%m%d%H%M%S'` MP3SERVER="nt-server-pdc" SERVERPORT=9090 netcat="$nc -c $MP3SERVER $SERVERPORT" SHUFFLE=$MP3/shuffle.album PLAY=$MP3/play REPEAT=$MP3/repeat.forever POWER=$MP3/power.on VOLUME=$MP3/volume100 BASS=$MP3/bass50 TREBLE=$MP3/treble50 rescan=0 bump=0 valid=0 invalid=0 list=0 PLAYLISTS=`ls -la $MP3/playlist.* | nawk -F "." '{print $NF}'` COMMANDLIST="\n\t*** Commands ***\n\npause\nstop\nplay\nshufflealbum\nshuffletrack\nshuffleoff\nrepeatoff\ \nrepeattrack\nrepeatforever\nrescan\nforward\nreverse\nlist\n\ \n\t*** Playlists ***\n" ERROR1="\nInput invalid. >>>$*<<<.\nFor a list of valid playlists type \"sc list\". Exiting...\n" # File Variables TMP1=/tmp/$progname.tmp1.$$ TMP2=/tmp/$progname.tmp2.$$ TMP3=/tmp/$progname.tmp3.$$ TMP4=/tmp/$progname.tmp4.$$ # Cleanup if our exit is dirty. trap "rm -fr $TMP1* $TMP2* $TMP3* $TMP4*;exit" 1 2 3 10 12 15 # If no options are provided by the user assume we are to turn off the player # otherwise set variables based on the provided input. if [ $# -lt 1 ] then POWER=$MP3/power.off $netcat < $POWER;sleep .3 echo "$SERIAL|$LOGNAME|POWER=$POWER" >> $MP3/sc.log else for x in $* do X=$x x=`echo $X|tr [A-Z] [a-z]` case $x in christianpopandrock|1) let valid=$valid+1;PLAYLIST=$MP3/playlist.ChristianPopAndRock ;; christiansoftrock|2) let valid=$valid+1;PLAYLIST=$MP3/playlist.ChristianSoftRock ;; christianhardrock|3) let valid=$valid+1;PLAYLIST=$MP3/playlist.ChristianHardRock ;; christianrock|4) let valid=$valid+1;PLAYLIST=$MP3/playlist.ChristianRock ;; classical|5) let valid=$valid+1;PLAYLIST=$MP3/playlist.Classical ;; christianpop|6) let valid=$valid+1;PLAYLIST=$MP3/playlist.ChristianPop ;; christianquiettime|7) let valid=$valid+1;PLAYLIST=$MP3/playlist.ChristianQuietTime ;; christmas|8) let valid=$valid+1;PLAYLIST=$MP3/playlist.Christmas ;; christianworkt[ou][on][ne]s|9) let valid=$valid+1;PLAYLIST=$MP3/playlist.ChristianWorkTunes ;; christianvocal|10) let valid=$valid+1;PLAYLIST=$MP3/playlist.ChristianVocal ;; christianworship|11) let valid=$valid+1;PLAYLIST=$MP3/playlist.ChristianWorship ;; christiankids|12) let valid=$valid+1;PLAYLIST=$MP3/playlist.ChristianKids ;; christian|13) let valid=$valid+1;PLAYLIST=$MP3/playlist.Christian ;; rock|14) let valid=$valid+1;PLAYLIST=$MP3/playlist.Rock ;; datedrock|15) let valid=$valid+1;PLAYLIST=$MP3/playlist.DatedRock ;; 50sand60srock|oldrock|16) let valid=$valid+1;PLAYLIST=$MP3/playlist.50sAnd60sRock ;; 70sAnd80sRock|classicrock|17) let valid=$valid+1;PLAYLIST=$MP3/playlist.70sAnd80sRock ;; softrock|18) let valid=$valid+1;PLAYLIST=$MP3/playlist.SoftRock ;; mediumrock|19) let valid=$valid+1;PLAYLIST=$MP3/playlist.MediumRock ;; hardrock|20) let valid=$valid+1;PLAYLIST=$MP3/playlist.HardRock ;; pop|21) let valid=$valid+1;PLAYLIST=$MP3/playlist.Pop ;; bigband|22) let valid=$valid+1;PLAYLIST=$MP3/playlist.BigBand ;; jazz|23) let valid=$valid+1;PLAYLIST=$MP3/playlist.Jazz ;; #goads|24) let valid=$valid+1;PLAYLIST=$MP3/playlist.Goads ;; country|25) let valid=$valid+1;PLAYLIST=$MP3/playlist.Country ;; pause) let valid=$valid+1;PLAY=$MP3/pause ;; stop) let valid=$valid+1;PLAY=$MP3/stop ;; play) let valid=$valid+1;PLAY=$MP3/play ;; shufflealbum) let valid=$valid+1;SHUFFLE=$MP3/shuffle.album ;; shuffletrack) let valid=$valid+1;SHUFFLE=$MP3/shuffle.track ;; shuffleoff) let valid=$valid+1;SHUFFLE=$MP3/shuffle.off ;; repeatoff) let valid=$valid+1;REPEAT=$MP3/repeat.off ;; repeattrack) let valid=$valid+1;REPEAT=$MP3/repeat.song ;; repeatforever) let valid=$valid+1;REPEAT=$MP3/repeat.forever ;; rescan) let valid=$valid+1;RESCAN=$MP3/rescan;rescan=1 ;; forward) let valid=$valid+1;SKIP=$MP3/track.forward;bump=1 ;; reverse) let valid=$valid+1;SKIP=$MP3/track.reverse;bump=1 ;; list) let valid=$valid+1;list=1 ;; *) let invalid=$invalid+1;bogus="$bogus \"$x\"" ;; esac done # Rescan MP3 folder for changes if [ $rescan -eq 1 ] then $netcat < $POWER;sleep .3 $netcat < $RESCAN;sleep .3 $netcat < $VOLUME;sleep .3 $netcat < $BASS;sleep .3 $netcat < $TREBLE echo "$SERIAL|$LOGNAME|POWER=$POWER|RESCAN=$RESCAN|VOLUME=$VOLUME" >> $MP3/sc.log # Check for any input that can be used. If there is none # notify the user. elif [ $valid -lt 1 ] then echo "$ERROR1" echo "$SERIAL|$LOGNAME|User ERROR1|valid=$valid" >> $MP3/sc.log rm -fr $TMP1* $TMP2* $TMP3* $TMP4* exit # Provide a method for the user to see how to use script elif [ $list -eq 1 ] then echo $COMMANDLIST ls -la $MP3/playlist.* | nawk -F "." '{print $NF}' echo "" echo "$SERIAL|$LOGNAME|List Commands|list=$list" >> $MP3/sc.log # Last check to check for commands outside playlist selection. # Here we can bump forward or backward one track and elif [ $bump -eq 1 ] then $netcat < $POWER;sleep .3 $netcat < $SKIP;sleep .3 $netcat < $VOLUME;sleep .3 $netcat < $BASS;sleep .3 $netcat < $TREBLE;sleep .3 echo "$SERIAL|$LOGNAME|POWER=$POWER|SKIP=$SKIP|VOLUME=$VOLUME" >> $MP3/sc.log # If none of the above are true we must be ready to select a playlist. # It should be noted that if the user selects more than one valid playlist # the only one that will be played is the last one in their list. This may # be changed in the future to include all the playlists but it may overload # the poor MP3 player so maybe not... else $netcat < $POWER;sleep .3 $netcat < $SHUFFLE;sleep .3 $netcat < $REPEAT;sleep .3 echo "$SERIAL|$LOGNAME|POWER=$POWER|SHUFFLE=$SHUFFLE|REPEAT=$REPEAT" >> $MP3/sc.log # Make it possible to change shuffle, repeat, or any other var in this list # without having a playlist and disturbing the current playlist. if [ $PLAYLIST ] then $netcat < $PLAYLIST;sleep .3 echo "$SERIAL|$LOGNAME|PLAYLIST=$PLAYLIST" >> $MP3/sc.log fi $netcat < $PLAY;sleep .3 $netcat < $VOLUME;sleep .3 $netcat < $BASS;sleep .3 $netcat < $TREBLE;sleep .3 echo "$SERIAL|$LOGNAME|PLAY=$PLAY|VOLUME=$VOLUME" >> $MP3/sc.log fi # Notify user there was bogus input even though there was enough # good input to get the job done if [ $invalid -ge 1 ] then BOGUS=`echo $bogus | sed 's/^ //'` echo "\nBogus value(s) ignored >>>$BOGUS<<<\n" echo "$SERIAL|$LOGNAME|bogus=$bogus" >> $MP3/sc.log fi fi # Cleanup rm -fr $TMP1* $TMP2* $TMP3* $TMP4*