tooner/tooner.sh

44 lines
1.0 KiB
Bash
Raw Normal View History

2021-03-29 23:46:20 -04:00
#!/bin/bash
2021-04-18 17:50:43 -04:00
! pgrep mpd > /dev/null && mpd
2021-03-29 23:46:20 -04:00
lastFile=/tmp/radioLast.$USER
2021-04-18 17:50:43 -04:00
nowPlaying=`mpc current -f "[%artist% - ]%title%"`
2021-04-18 18:46:54 -04:00
nowPlaying=`echo $nowPlaying | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g'`
2021-04-18 17:50:43 -04:00
width=$((${#nowPlaying} > 30 ? ${#nowPlaying} : 30))
2021-03-29 23:46:20 -04:00
if [ $# -eq 0 ]; then
stationFile=~/.stations
else
stationFile=$1
fi
stations=`cat $stationFile`
if [ -f "$lastFile" ]; then
last="$(cat $lastFile)"
else
touch $lastFile
chmod 660 $lastFile
fi
names=()
urls=()
IFS=$'\n'
for item in $stations; do
if [ "$(echo $item | head -c 1)" != "#" ]; then
IFS='|' read -r name url <<< "$item"
names+=("$name")
urls+=("$url")
fi
done
[ "${#names[@]}" -lt 10 ] && l=${#names[@]} || l=10
2021-09-10 17:47:20 -04:00
choice=`echo "${names[*]}" | rofi -i -dmenu -format i -mesg "<small>$nowPlaying</small>" -l $l -width -$width -location 7 -p "Radio" -no-custom -select $last`
2021-03-29 23:46:20 -04:00
if [ ! -z "$choice" ]; then
mpc clear
mpc add ${urls[choice]}
mpc play
echo ${names[choice]} > $lastFile
fi