summaryrefslogtreecommitdiff
path: root/radio.sh
blob: cecd9d0e5713634f058b8ba19ce403eb64ecdb17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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}"