Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 65 lines (52 sloc) 1.36 KB
#!/usr/bin/env bash
# radio.sh
# Author: William Woodruff
# ------------------------
# Stream various radio stations defined in ~/.radiorc.
# Requires mpv and GNU bash 4.0.
# ------------------------
# This code is licensed by William Woodruff under the MIT License.
# http://opensource.org/licenses/MIT
player="mpv"
playeropts="--force-window=no --no-ytdl"
command="${1:-usage}"
function error() {
>&2 echo "Fatal: ${*}. Exiting."
exit 2
}
function installed() {
cmd=$(command -v "${1}")
[[ -n "${cmd}" ]] && [[ -f "${cmd}" ]]
return ${?}
}
function usage() {
echo "Usage: $(basename "${0}") <station|list>"
list_stations
exit
}
function list_stations() {
echo "Available stations:"
for station in "${!stations[@]}"; do
echo -e "\t${station}"
done
}
[[ -f ~/.radiorc ]] || error "Missing ~/.radiorc"
[[ "${BASH_VERSINFO[0]}" -lt 4 ]] && error "GNU bash 4.0 or later is required"
installed "${player}" || error "Missing dependency: '${player}'"
declare -A stations
source ~/.radiorc
[[ -z "${stations[0]}" ]] || error "Missing radio stations in ~/.radiorc"
if [[ "${command}" = "usage" ]]; then
usage
elif [[ "${command}" = "list" ]]; then
list_stations
else
station="${stations["${command}"]}"
if [[ -z "${station}" ]]; then
echo "No such station: '${command}'."
list_stations
exit 1
else
eval "${player} ${playeropts} ${station}"
fi
fi