From 2f6b59970e1f772b39faccd0a8d91857cc5b1d0b Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 3 Aug 2022 16:55:15 +0200 Subject: Add tv.sh --- tv.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 tv.sh diff --git a/tv.sh b/tv.sh new file mode 100755 index 0000000..fdfc70e --- /dev/null +++ b/tv.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# vim: shiftwidth=4 tabstop=4 noexpandtab + +# constants +data_repo="${HOME}/.local/share/mydata" +data_rel="tables/tv.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}" -- cgit v1.2.3-70-g09d2