diff options
author | xengineering <me@xengineering.eu> | 2022-08-03 16:46:19 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2022-08-03 16:46:19 +0200 |
commit | a54e6a7414b61cdf136e71ad62137f34541ecc64 (patch) | |
tree | 1060ced1ebb0b9c13bae45e99aab4bdda01e35d1 /radio.sh | |
parent | 65b4a15248124a926f0069f200aecb1102d5dcd7 (diff) | |
download | scripts-a54e6a7414b61cdf136e71ad62137f34541ecc64.tar scripts-a54e6a7414b61cdf136e71ad62137f34541ecc64.tar.zst scripts-a54e6a7414b61cdf136e71ad62137f34541ecc64.zip |
Add radio.sh
Diffstat (limited to 'radio.sh')
-rwxr-xr-x | radio.sh | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/radio.sh b/radio.sh new file mode 100755 index 0000000..cecd9d0 --- /dev/null +++ b/radio.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# vim: shiftwidth=4 tabstop=4 noexpandtab + +# constants +data_repo="${HOME}/.local/share/mydata" +data_rel="tables/radio.tsv" +data_abs="${data_repo}/${data_rel}" + +# read station from command line arguments +station="$1" + +# set a handler for keyboard interrupts +trap 'exit 0' 2 15 + +# check dependency and warn user if necessary +if ! which mpv > /dev/null 2>&1 +then + echo 'You have to install mpv (e.g. sudo pacman -S mpv mpv-mpris)' + exit 1 +fi + +# check if data file exists +if ! [ -f "${data_abs}" ] +then + echo "Data file '""${data_abs}""' not found." + exit 1 +fi + +# translate sender name to URL +address="$(grep "${station}" "${data_abs}" | awk -F '\t' '{print $2}')" +if [ "${address}" = "" ] +then + echo "Could not translate station ${station} to URL." + exit 1 +fi + +# stream from address +echo "Streaming ${station} from ${address}." +mpv "${address}" |