Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #by Csandriel
- #22.02.17
- #plays radio and can save track/artist data for later downloading
- #uses mpg123 for mp3 streaming
- #username, will be used to launch the script, if it called by root.
- #To avoid ussues with permissions
- USER=user
- #keep track of all played traks ^_^. Must have liberal permissions
- #items for the best-list is taken from the tail of this "journal"
- LOG="/home/bin/.mus.log"
- #these files too must be accesible for writing to everyone
- #best list
- BEST="/store0/mp3/xes-bestmusic.log"
- #will run in background. Need a reference to kill with.
- PIDFILE="/home/bin/.xes.pid"
- #radio address:port. May be extracted from playlist distributed by station.
- #TODO:add an option to switch stantions. Maybe from configfile.
- ADDRESS="http://46.163.111.34:8030"
- USAGE_MSG="Invalid argument! \n Usage: xes [-k|-s|-l|-clear] \n
- where \n -k -- kill; \n -s -- save to best-list \n -l -- roll-out best-list
- -clear -- clear best-list"
- RESTART_MSG=\'"$PIDFILE' exists. It seems xes have been launched yet. Killing/Cleaning/Restart. \n Log-file will be reseted."
- #if launched as root then restart script as user
- if [ $UID -eq 0 ] ; then echo "DROP ROOT & recurse"; echo "$0 $@"; su $USER -c "$0 $@"; exit; fi
- dokill () {
- cat "$PIDFILE"|xargs kill; rm "$PIDFILE" "$LOG"
- }
- case $1 in
- -k) if [ -f $PIDFILE ] ; then dokill ; else echo "xes is down. There is left only to kill yourself"; fi
- ;;
- -s) cat $LOG|tail -n1|sed "s_.*Title=\([^;]*\).*_\1_" >> $BEST
- ;;
- -l) cat "$BEST"
- ;;
- -clear) echo "BEST-LIST WILL BE CLEANCED! Are You sure? [y/<any key>]"
- read r; if [ "$r" == "y" ] ; then > "$BEST" ; else exit 0; fi
- ;;
- *) if [ $# -eq 0 ]
- then
- if [ -f $PIDFILE ]
- then echo -e $RESTART_MSG; dokill;
- fi
- mpg123 "$ADDRESS" &> $LOG & PID=$!
- echo "$PID" > "$PIDFILE"
- else echo -e "$USAGE_MSG"
- exit 1
- fi
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement