Radio station picker for mpd using rofi
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1KB

  1. #!/bin/bash
  2. ! pgrep mpd > /dev/null && mpd
  3. lastFile=/tmp/radioLast.$USER
  4. nowPlaying=`mpc current -f "[%artist% - ]%title%"`
  5. nowPlaying=`echo "$nowPlaying" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g'`
  6. width=$((${#nowPlaying} > 30 ? ${#nowPlaying} : 30))
  7. if [ $# -eq 0 ]; then
  8. stationFile=~/.stations
  9. else
  10. stationFile=$1
  11. fi
  12. stations=`cat $stationFile`
  13. if [ -f "$lastFile" ]; then
  14. last="$(cat $lastFile)"
  15. else
  16. touch $lastFile
  17. chmod 660 $lastFile
  18. fi
  19. names=()
  20. urls=()
  21. IFS=$'\n'
  22. for item in $stations; do
  23. if [ "$(echo $item | head -c 1)" != "#" ]; then
  24. IFS='|' read -r name url <<< "$item"
  25. names+=("$name")
  26. urls+=("$url")
  27. fi
  28. done
  29. [ "${#names[@]}" -lt 10 ] && l=${#names[@]} || l=10
  30. choice=`echo "${names[*]}" | rofi -i -dmenu -format i -mesg "<small>$nowPlaying</small>" -l $l -width -$width -location 7 -p "Radio" -no-custom -select $last -theme-str "#window { width: 50ch; }"`
  31. if [ ! -z "$choice" ]; then
  32. mpc clear > /dev/null
  33. mpc add ${urls[choice]} > /dev/null
  34. mpc play > /dev/null
  35. echo ${names[choice]} > $lastFile
  36. fi