-
Notifications
You must be signed in to change notification settings - Fork 0
/
listentoradio
executable file
·115 lines (102 loc) · 3.08 KB
/
listentoradio
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
########################################################################
# A simple utility to allow listening to digitally imported from CLI
#
# by Steven Saus
#
# Licensed under a Creative Commons BY-SA 3.0 Unported license
# To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.
#
########################################################################
########################################################################
# Declarations
########################################################################
TEMPDIR=$(mktemp -d)
touch $TEMPDIR/tempjson.json
touch $TEMPDIR/tempkey.txt
touch $TEMPDIR/tempname.txt
touch $TEMPDIR/tempdesc.text
touch $TEMPDIR/stationtemp.text
TEMPJSON="$TEMPDIR/tempjson.json"
TEMPKEY="$TEMPDIR/tempkey.txt"
TEMPNAME="$TEMPDIR/tempname.txt"
TEMPDESC="$TEMPDIR/tempdesc.text"
TEMPSTATION="$TEMPDIR/stationtemp.text"
TermWidth=$(tput cols)
#get userkey
userkey=$(head -1 $HOME/.config/diuserkey.rc)
if [ "$1" == "--gui" ];then
shift
rofi_bin=$(which rofi)
pick_bin="${rofi_bin} -i -dmenu 'Which station?' -theme DarkBlue"
else
if [ -f $(which fzf) ];then
pick_bin=$(which fzf)
else
pick_bin=$(which pick)
fi
fi
if [ -f $(which mplayer) ];then
mplayer_bin=$(which mplayer)
else
mplayer_bin=$(which mpv)
fi
#get channel list
VarA=$(curl https://www.radiotunes.com | awk -F "di.app.start" '{ print $2 }' | grep -e ")" )
VarA=${VarA#?}
VarA=${VarA%??}
echo "$VarA" > "$TEMPJSON"
OLDIFS=$IFS
IFS=''
#parse channel list
cat "$TEMPJSON" | jq -r -M '.channels[] | .name' > $TEMPNAME
readarray -t NameArr < $TEMPNAME
cat "$TEMPJSON" | jq -r -M '.channels[] | .description' > $TEMPDESC
readarray -t DescArr < $TEMPDESC
cat "$TEMPJSON" | jq -r -M '.channels[] | .key' > $TEMPKEY
readarray -t KeyArr < $TEMPKEY
IFS=$OLDIFS
channels=${#KeyArr[@]}
# use for loop read all stations
for (( i=0; i<${channels}; i++ ));
do
size=${#KeyArr[$i]}
size=$((size + 1))
spacing=$((TermWidth - size))
display1=$(echo "${NameArr[$i]} : ${DescArr[$i]}" | cut -c 1-${spacing} )
echo "$display1:${KeyArr[$i]}" >> $TEMPSTATION
done
stnm=$(cat $TEMPSTATION | ${pick_bin} | awk -F ":" '{print $3}')
stationname=$(printf "%s_aac" "$stnm")
stationurl=$(echo "http://prem4.radiotunes.com:80/$stationname?$userkey")
echo "$stationurl"
if [ "$1" == "--mpd" ]; then
mpc add "$stationurl"
Position=$(mpc playlist | wc -l )
mpc play "$Position"
else
if [ "$1" == "--url" ]; then
echo "${stationurl}"
exit 0
else
"${mplayer_bin}" -really-quiet "$stationurl" -user-agent "AudioAddict-di/3.2.0.3240 Android/5.1" &
mplayer_PID=$!
if [ -f $(which cava) ];then
echo "Loading $stationname... quit cava to exit the stream."
sleep 5
export TERM=xterm-256color
cava
else
echo "Listening to $stationname..."
echo "Press any key to exit the stream."
read
fi
kill -9 ${mplayer_PID}
fi
fi
rm "$TEMPJSON"
rm "$TEMPKEY"
rm "$TEMPNAME"
rm "$TEMPDESC"
rm "$TEMPSTATION"
rmdir "$TEMPDIR"