+'http://di.fm/' player.
[nethome.git] / bin / engine-di.fm
1 #! /bin/bash
2 #
3 # $Id$
4
5
6 if [ "$1" = "build" ];then
7         old="`find -maxdepth 1 -name "di.fm-*" -type l`"
8         if [ -z "$old" ];then echo >&2 "No existing symlinks found.";exit 1;fi
9         newdashed="`wget -q -O - http://di.fm/|tr ' ' '\n' \
10                         |perl -n -e 's/^.*"([^"]*[.](?:pls|asx))".*$/$1/ and print;' \
11                         |grep -v '^/aacplus/' \
12                         |tr / -`"
13         if [ -z "$newdashed" ];then echo >&2 "Failed to download the new listing found.";exit 1;fi
14         TARGET="engine-di.fm"
15         if [ ! -x "$TARGET" ];then echo >&2 "Target engine $TARGET not found.";exit 1;fi
16         rm -f $old
17         PREFIX="di.fm"
18         for pathdashed in $newdashed;do
19                 ln -s "$TARGET" "$PREFIX$pathdashed"
20         done
21         echo OK
22         exit 0
23 fi
24
25 set -ex
26 pathslashed="`basename "$0"|sed 's/^di[.]fm//'|tr - /`"
27 #MEDIA=mp3
28 MEDIA=aacplus
29 if false;then
30         stream="`lynx -source http://di.fm${pathslashed}|sed -n 's/^File1=//p'|tr -d '\r'`"
31         exec mplayer -cache 128 "$stream"
32         exit 1
33 else
34         streamlist="`lynx -source http://di.fm${pathslashed}|sed -n \
35                         -e 's/^File[0-9]*=//p' \
36                         -e 's#^.*"\(mms://[^"]*\)".*$#\1#p' \
37                         |tr -d '\r'`"
38         for stream in $streamlist;do
39                 # Using "set -e" here:
40                 # mplayer rc 0 on failure to read the stream
41                 # mplayer rc 0 on 'q'
42                 # mplayer rc 1 on ctrl-c
43                 mplayer -cache 128 "$stream"
44         done
45 fi