-
Notifications
You must be signed in to change notification settings - Fork 1
/
sfdrs.sh
executable file
·151 lines (127 loc) · 3.54 KB
/
sfdrs.sh
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash -e
########################################################################
#* This script helps you to stay informed while working - at least
#* if your swiss and used to a certain level of noice while working...
#* Basically it is a wrapper to watch SF DRS 10vor10 and Rundschau
#* Podcasts from the command line with the help of mplayer.
#
########################################################################
# author/copyright: <[email protected]>
# license: gladly sharing with the universe and any lifeform,
# be it naturally born or constructed, alien or kin..
########################################################################
[ "$1" == "debug" ] && shift && set -x
## variables ##
### you may copy the following variables into this file for having your own
### local config ...
#conffile=~/.rundschau.sh
### {{{
rundschau_url="http://www.srf.ch/feed/podcast/hd/49863a84-1ab7-4abb-8e69-d8e8bda6c989.xml"
zvz_url="https://www.srf.ch/feed/podcast/hd/c38cc259-b5cd-4ac1-b901-e3fddd901a3d.xml"
### }}}
# The system tools we gladly use. Thank you!
declare -A sys_tools
sys_tools=( ["_awk"]="/usr/bin/awk"
["_cat"]="/bin/cat"
["_cp"]="/bin/cp"
["_grep"]="/bin/grep"
["_mkdir"]="/bin/mkdir"
["_mplayer"]="/usr/bin/mplayer"
["_pwd"]="/bin/pwd"
["_rm"]="/bin/rm"
["_rmdir"]="/bin/rmdir"
["_sed"]="/bin/sed"
["_tr"]="/usr/bin/tr"
["_wget"]="/usr/bin/wget"
["_xml2"]="/usr/bin/xml2" )
danger_tools=( "_cp" "_cat" "_dd" "_mkdir" "_rm" "_rmdir" )
## functions ##
print_usage()
{
echo "usage: $0"
}
print_help()
{
print_usage
$_grep "^#\* " $0 | $_sed 's;^#\*;;'
}
die()
{
echo "$@"
exit 1
}
error()
{
print_usage
echo ""
die "Error: $@"
}
## logic ##
## first set the system tools
for t in ${!sys_tools[@]} ; do
if [ -x "${sys_tools[$t]##* }" ] ; then
export ${t}="${sys_tools[$t]}"
else
error "Missing system tool: ${sys_tools[$t]##* } must be installed."
fi
done
[ -r "$conffile" ] && . $conffile
playlatest=1
#* options:
while true ; do
case "$1" in
#* -h |--help print this help
-h|--help)
print_help
exit 0
;;
#* -l |--latest show the latest right away
-l|--latest)
playlatest=0
;;
-*|--*)
error "option $1 not supported"
;;
#* 10vor10 consider 10vor10
10*)
url=${zvz_url}
;;
#* rundschau consider rundschau
r*)
url=$rundschau_url
;;
*)
break
;;
esac
shift
done
if [ -z "$url" ] ; then
echo "Wa wetsch luege? 10vor10 oder rondschau?"
read answer
if [ "$answer" == "10vor10" ] ; then
url=${zvz_url}
elif [ "$answer" == "rondschau" ] ; then
url=$rundschau_url
else
echo "Hani ned verstande, sorry..."
exit 1
fi
fi
channels=( $($_wget -O - "$url" | $_xml2 | $_grep "/rss/channel/item/enclosure/@url" | $_awk 'BEGIN{FS="="}{print $2}') )
if [ $playlatest -eq 0 ] ; then
$_mplayer ${channels[0]}
else
echo "Die channels hani gfonde.."
i=0
for c in ${channels[@]} ; do
echo "$i) $c"
let ++i
done
echo "wele wotsch? oder eifach nuet"
read answer
if [ -n "$answer" ] ; then
$_mplayer -zoom -framedrop ${channels[answer]}
fi
fi
exit 0