#!/bin/bash # To add your own stations, put them in ~/.config/radio.sh.conf 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" $( [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/radio.sh.conf" ]] && source "${XDG_CONFIG_HOME:-$HOME/.config}/radio.sh.conf") ) if [[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/radio.sh.conf" ]]; then while IFS="=" read -r key value; do if [[ "$key" =~ ^\[.*\]$ && "$value" =~ ^\".*\"$ ]]; then key="${key#[}" key="${key%]}" value="${value#\"}" value="${value%\"}" stations["$key"]="$value" else echo "Error: invalid format in ${XDG_CONFIG_HOME:-$HOME/.config}/radio.sh.conf" >&2 exit 1 fi done < <(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' "${XDG_CONFIG_HOME:-$HOME/.config}/radio.sh.conf") 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 "Cast" \ --help-button \ --help-label "Exit" \ --menu "Select a radio station" -1 -1 -1 "${menuList[@]}" --stdout)" menuCode=$? if [[ $menuCode -eq 2 ]]; then exit 0 fi export url if [[ ${menuCode} -eq 1 ]]; then trap - SIGINT SIGTERM EXIT if ! command -v mkchromecast &> /dev/null ; then echo "Please install mkchromecast to use this functionality." fi mkchromecast --encoder-backend ffmpeg --source-url "$url" --control sleep 2 exit 0 elif [[ ${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