fb9778ca760cc6dbc057966f363606bba0800a58
[shellsnippets/shellsnippets.git] / bash-ksh / L365
1 #!/bin/mksh
2 # $MirOS: contrib/hosted/tg/L365,v 1.1 2012/07/29 17:48:01 tg Exp $
3 #-
4 # Player for music streams from live365.com (not affiliated).
5
6 # Inline-edit this script to define your credentials:
7 USERID='myusername'
8 PASSWD='my!secret!'
9
10 # Code follows.
11
12 # disabled as mpg123 with live365 is too unreliable (lack of caching)
13 #if [[ $1 = -m ]]; then
14         player='mplayer -cache 256'
15 #       shift
16 #else
17 #       player=mpg123
18 #fi
19
20 STATION=$1
21
22 cd /
23 if ! T=$(mktemp -d /tmp/L365.XXXXXXXXXX) || [[ ! -d $T/. ]]; then
24         print -u2 Error creating temporary directory.
25         exit 255
26 fi
27
28 cd "$T"
29 if ! curl --cookie-jar curlcookies --output curldump --location-trusted \
30     "http://www.live365.com/cgi-bin/login.cgi?url=http://www.live365.com/index.live&membername=${USERID}&password=${PASSWD}"; then
31         cd /
32         rm -rf "$T"
33         print -u2 Error logging in.
34         exit 2
35 fi
36
37 SANE=$(fgrep SaneID curlcookies | cut -f7)
38 SESS=$(fgrep sessionid curlcookies | cut -f7 | sed "s/${USERID}%3A//")
39
40 cd /
41 rm -rf "$T"
42
43 exec $player "http://www.live365.com/play/${STATION}?SaneID=${SANE}&membername=${USERID}&session=${SESS}"