+unset http_proxy
[nethome.git] / bin / engine-di.fm
1 #! /bin/bash
2 #
3 # $Id$
4
5
6 echo >&2 "FIXME: http_proxy"
7 unset http_proxy
8
9
10 if [ "$1" = "build" ];then
11         old="`find -maxdepth 1 '(' -name "di.fm-*" -o -name "sky.fm-*" ')' -type l`"
12         if [ -z "$old" ];then echo >&2 "No existing symlinks found.";exit 1;fi
13         for site in di.fm sky.fm;do
14                 newdashed="`wget -q -O - http://$site/|tr ' ' '\n' \
15                                 |perl -n -e '
16                                                 s{^.*"(?:http://www.'$site')?([^":]*(?<!_low)[.](?:pls|asx))".*$}{$1} or next;
17                                                 m{^/aacplus/} and next;
18                                                 tr{/}{-};
19                                                 print;
20                                                 ' \
21                                 `"
22                 if [ -z "$newdashed" ];then echo >&2 "Failed to download the new listing found.";exit 1;fi
23                 TARGET="engine-di.fm"
24                 if [ ! -x "$TARGET" ];then echo >&2 "Target engine $TARGET not found.";exit 1;fi
25                 rm -f $old
26                 old=""
27                 PREFIX="$site"
28                 for pathdashed in $newdashed;do
29                         test -L "$PREFIX$pathdashed" && continue
30                         ln -s "$TARGET" "$PREFIX$pathdashed"
31                 done
32         done
33         echo OK
34         exit 0
35 fi
36
37 set -ex
38 pathslashed="`basename "$0"|tr - /`"
39 if false;then
40         stream="`lynx -source http://di.fm${pathslashed}|sed -n 's/^File1=//p'|tr -d '\r'`"
41         exec mplayer -ao oss:/dev/dsp -cache 128 "$stream" "$@"
42         exit 1
43 else
44         while :;do
45                 streamlist="`lynx -source http://${pathslashed}|sed -n \
46                                 -e 's/^File[0-9]*=//p' \
47                                 -e 's#^.*"\(mms://[^"]*\)".*$#\1#p' \
48                                 |tr -d '\r'`"
49                 for stream in $streamlist;do
50                         # Using "set -e" here:
51                         # mplayer rc 0 on failure to read the stream
52                         # mplayer rc 0 on 'q'
53                         # mplayer rc 1 on ctrl-c
54                         ip="`  echo "$stream"|sed -n 's#^http://\([^:/]*\).*$#\1#p'`"
55                         if [ -n "$ip" ];then
56                                 port="`echo "$stream"|sed -n 's#^http://[^:/]*:\([0-9][0-9]*\).*$#\1#p'`"
57                                 port="${port:-80}"
58                                 echo >&2 "Checking $stream -> {$ip}:{$port} ..."
59                                 if ! nc -w 2 "$ip" "$port";then
60                                         echo >&2 "TIMEOUT: $stream"
61                                         continue
62                                 fi
63                         fi
64                         #mplayer -ao alsa:device=hw=0 -cache 512 "$stream" "$@"
65                         mplayer -cache 512 "$stream" "$@"
66                 done
67         done
68 fi