#! /bin/zsh PLAYER='mpv' PLAYER_OPTS=('--no-video') LAST_STATION_PATH="$HOME/.last_station" FIFO=1 FIFO_PATH="$HOME/.ztream_fifo" # THIS FILE WILL GET DELETED ON STARTUP UNCONDITIONALLY DMENU_OPTS=(-w 0.6 -y 0.2) OTHER_PLAYERS=(spotify mocp) typeset -A stations stations=('beatblender' http://sfstream1.somafm.com:8384 'cliq hop' http://mp2.somafm.com:2668 'drone zone' http://mp4.somafm.com:80 'Def Con' http://sfstream1.somafm.com:6200 'BassDrive' http://shouthost.com.17.streams.bassdrive.com:8200 'dubstep beyond' http://mp1.somafm.com:8400 'groove salad' http://voxsc1.somafm.com:8032 'sonic universe' http://mp2.somafm.com:8604 'YT: MajesticCasual' '--playlist=/home/bryan/.builds/ztream/MajesticCasual' 'YT: Kasger' '--playlist=/home/bryan/.builds/ztream/KasgerOfficial' ) ############################################################################### # Unless you have an idea of what you're doing, there's no need to head below. ############################################################################### function play_station() { pkill $PLAYER for plyr in "${OTHER_PLAYERS[@]}"; do pkill $plyr; done echo $station >! $LAST_STATION_PATH if [ $FIFO -eq 1 ]; then if [ -e $FIFO_PATH ]; then rm "$FIFO_PATH" fi mkfifo "$FIFO_PATH" $PLAYER "${PLAYER_OPTS[@]}" --input-file="$FIFO_PATH" $stations[$station] 2>&1 >/dev/null & else $PLAYER "${PLAYER_OPTS[@]}" $stations[$station] 2>&1 >/dev/null & fi; } function parse_action() { if [ -n $action ]; then if [ $action = 'change' ]; then # pick a new station station=$(print -r -l ${(k)stations} | sort | dmenu "${DMENU_OPTS[@]}" "$@" -p "Station: ") if [ -n $station ]; then play_station $station fi elif [ $action = 'random' ]; then # pick a random station from above integer index=$RANDOM%${#${(k)stations}}+1 station=${${(k)stations}[$index]} echo "Chose '$station'" play_station $station elif [ $action = 'last' ]; then # choose the last station station=$(cat $LAST_STATION_PATH) play_station $station elif [ $action = 'stop' ]; then # STAHP pkill $PLAYER fi fi } action="" actions=('change' 'random' 'last' 'stop') action=$(print -r -l ${actions} | dmenu "${DMENU_OPTS[@]}" "$@" -p "Action: ") parse_action $@