diff --git a/radio.sh b/radio.sh new file mode 100755 index 0000000..15ccb7c --- /dev/null +++ b/radio.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# To add your own stations, put them in ~/.config/radio.sh.conf +if [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/radio.sh.conf" ]]; then + source "${XDG_CONFIG_HOME:-$HOME/.config}/radio.sh.conf" +else + declare -A stations=( + [NS Hit Radio ]="https://listen.nshitradio.com/" + [The Metal Plague ]="http://46.4.40.246:8386/" + [The True Monster ]="http://procyon.shoutca.st:8428/stream?fbclid=IwAR37SD7AucBHp-woBj7QyoeQPzQkCTW2BBI-CR1Q9W1hIMvIJhV9iQRQYMs" + [Thunder Rock ]="http://ice10.securenetsystems.net/KTHU2" + ) +fi + + +if ! command -v mpv &> /dev/null ; then + echo "Please install mpv." + exit 1 +fi + +# Handle subprocesses that may not close with the main program. +trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT + +# Dialog accessibility +export DIALOGOPTS='--no-lines --visit-items' + +for i in "${!stations[@]}" ; do + menuList+=("${stations[$i]}" "${i}") +done + +url="$(dialog --clear \ + --backtitle "Storm radio" \ + --no-tags \ + --extra-button \ + --extra-label "Record and Listen" \ + --ok-label "Listen" \ + --cancel-label "Exit" \ + --menu "Select a radio station" -1 -1 -1 "${menuList[@]}" --stdout)" +menuCode=$? +if [[ $menuCode -eq 1 ]]; then + exit 0 +fi + +if [[ ${menuCode} -eq 3 ]]; then + if ! command -v streamripper &> /dev/null ; then + echo "Please install streamripper." + exit 1 + fi + mkdir -p ~/stream + streamripper "${url}" --quiet -r -z -d ~/stream & + echo "Starting stream recording..." + sleep 3 + mpv --quiet --no-video --volume="${1:-100}" "http://localhost:8000" +else + mpv --quiet --no-video --volume="${1:-100}" "${url}" +fi + +exit 0