Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- #22.02.17
- #08.01.18
- #Csandriel
- #depends on: mpv
- #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/.xes-mus.log"
- #these files too must be accesible for writing to everyone
- #best list
- BEST="/home/bin/.xes-bestmusic.log"
- #We'll run in background. Need a reference to be killed with.
- PIDFILE="/home/bin/.xes.pid"
- ADDRESSeS=(\
- #radio address:port. Put additional adresses here. Obey '\' finisher in all strings except the last
- "http://radio.heavy-music.ru:8107/320" \
- "https://stream.laut.fm/moshhead-gothic" \
- "http://streams.radiobob.de/gothic/mp3" \
- "https://stream.spreeradio.de/spree-live/mp3" \
- "https://0n-gothic.radionetz.de/0n-gothic.mp3" \
- "http://channels.fonotron.ru/stream/Chan_74_256.mp3" \
- "http://chanson.hostingradio.ru:8041/chanson256.mp3" \
- "http://ic2.101.ru:8000/v11_1" \
- "http://ep256.hostingradio.ru:8052/europaplus256.mp3" \
- "http://video.tvr.by:8000/culture" \
- "http://air2.radiorecord.ru:805/mdl_320"
- "http://ice912.echo.msk.ru:9120/32.aac" \
- "http://rfe04.akacast.akamaistream.net/7/894/437768/v1/ibb/akacast.akamaistream.net/rfe04" \
- "http://rfe10.akacast.akamaistream.net/7/894/437768/v1/ibb/akacast.akamaistream.net/rfe10" \
- "http://stream.euroradio.fm:8000/euroradio1"
- )
- USAGE_MSG=" \n Usage: xes [-k|-s|-l|-c|-h <number>|-r|-v <number>] \n
- where \n -k -- kill; \n -s -- save current track to the best-list \n -l -- roll-out the best-list
- -r -- clear the best-list \n -n -- show current playing track \n -c <number> -- select a chanell; if not selected CHAN 0 is used \n -v <number> -- set volume in percetage; if not set then 100 by default"
- #username.
- USER=user
- 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"; STRING="$@"; su $USER -c "$0 $STRING"; exit; fi
- dokill () {
- cat "$PIDFILE"|xargs kill; rm "$PIDFILE" "$LOG"
- }
- doplay (){
- #-----------------------
- #is xes running?
- if [ -f $PIDFILE ]; then
- echo -e $RESTART_MSG; dokill;
- fi
- #-----------------------
- #is $CHAN a valid index?
- if [ $((CHAN)) -gt $((${#ADDRESSeS[@]}-1)) ]; then
- echo "lenght of ADDRESSeS= ${#ADDRESSeS[@]}"
- echo "requested CHAN index exeeds existig array"
- exit 1;
- fi
- #-----------------------
- #if $CHAN or $VOL is not set then using by defaults
- ADDRESS=${ADDRESSeS[${CHAN:-0}]}
- echo "address set to $ADDRESS; "
- VOLUME=${VOL:-100}
- echo "volume set to $VOLUME"
- mpv --volume="$VOLUME" "$ADDRESS" 1>"$LOG" 2>/dev/null &
- PID=$!
- echo '$PID='"$PID"
- echo "$PID" > "$PIDFILE"
- }
- while getopts kslnrv:c: Option
- do
- case "$Option" in
- "k") if [ -f $PIDFILE ] ; then dokill ;
- else echo "xes is down. There is left only to kill yourself"; fi
- exit 0
- ;;
- "s") cat $LOG|tail -n 2|grep icy|sed "s_.*title:\([^;]*\).*_\1_" >> $BEST
- exit 0
- ;;
- "l") cat "$BEST"
- exit 0
- ;;
- "n") echo "Now playing:"
- cat $LOG|tail -n2|grep icy|sed "s_.*title:\([^;]*\).*_\1_"
- exit 0
- ;;
- "r") echo "BEST-LIST WILL BE CLEANCED! Are You sure? [y/<any key>]"
- read r; if [ "$r" == "y" ] ; then > "$BEST" ; else exit 0; fi
- exit 0
- ;;
- "c") CHAN=$OPTARG
- ;;
- "v") VOL=$OPTARG
- ;;
- * ) echo -e "$USAGE_MSG"
- exit 1
- ;;
- esac
- done
- doplay
Add Comment
Please, Sign In to add comment