From 9c8c253d03370e055a65cc7e4c9e341ff6c65de6 Mon Sep 17 00:00:00 2001 From: stormdragon2976 Date: Sat, 11 Feb 2023 16:50:24 -0500 Subject: [PATCH] You no longer have to declare an array in the configuration file. just add the stations in the format [station name]="url" --- radio.sh | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/radio.sh b/radio.sh index 15ccb7c..644d769 100755 --- a/radio.sh +++ b/radio.sh @@ -1,15 +1,26 @@ #!/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 - 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" - ) + 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