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 | #!/bin/bash
##spielwasab.sh
##stream-player testscript for mplayer
#
#
export STREAM
function interactive
{
#read playlist - thx to comm@nder ;-)
LINE_NUMBER=1
while read LINE
do
PLAYLIST[$LINE_NUMBER]="$LINE"
LINE_NUMBER=$(($LINE_NUMBER+1))
done < playlist
echo "0: (play random stream)"
COUNT=1
until [ ${#PLAYLIST[*]} -lt ${COUNT} ]
do
echo "$COUNT: ${PLAYLIST[$COUNT]}"
COUNT=$(($COUNT+1))
done
while :
do
echo -n "Please select no. of stream to play, q to exit (0-"${#PLAYLIST[*]}") "
read SELECTION
SELECTION=${SELECTION##*[^0-9,q]*}
if [ "$SELECTION" = "q" ]; then
echo "Bye!"
exit 0
elif [ -z "$SELECTION" ]; then
echo "Illegal entry"
elif [ "$SELECTION" = "0" ]; then
let "RNDM = $RANDOM % ${#PLAYLIST[*]} + 1"
STREAM="${PLAYLIST[$RNDM]}"
check
elif [ "$SELECTION" -le ${#PLAYLIST[*]} ]; then
STREAM="${PLAYLIST[$SELECTION]}"
check
else
echo "No." "$SELECTION" "is not a valid stream"
fi
done
}
function check
{
echo "$STREAM" debug-output1
echo "${STREAM##*.}" debug-output2
if [ "${STREAM##*.}" = "nsv" ]; then
echo "Nullsoft video stream detected"
ARGS="-cache 1024 -vf scale=640:-3:0:0:100,unsharp=l3x3:1c3x3:1 -sws 7"
playit
elif [ "${STREAM##*.}" = "rm" ]; then
echo "Realmedia stream detected"
ARGS="-cache 128 -bandwidth 99999"
playit
elif [ "${STREAM##*.}" = "asx" ]; then
echo "M$ stream detected"
ARGS="-cache 128"
playit
else
echo "${STREAM%%://*}" debug-output3
if [ "${STREAM%%://*}" = "http" ]; then
echo "Unknown stream over http protocol detected"
ARGS=" "
playit
elif [ "${STREAM%%://*}" = "rtsp" ]; then
echo "Unknown stream over rtsp protocol detected"
ARGS=" "
playit
elif [ "${STREAM%%://*}" = "mms" ]; then
echo "Unknown stream over mms protocol detected"
ARGS=" "
playit
else
echo "Hmpfff. What do we play today?"
ARGS=" "
playit
fi
fi
}
function playit
{
echo "now playing" "$STREAM" "press q to exit"
mplayer -quiet $ARGS $STREAM >/dev/null 2>/tmp/mperror.log
if [ $? -gt 0 ]; then
echo "Mplayer returned an error:"
cat /tmp/mperror.log
echo -n "Try again? (y/N) "
read ERR
if [ "$ERR" = "y" ]; then
playit
else
interactive
fi
fi
interactive
}
if [ $# -gt 0 ]; then
STREAM=$1
check
else
if [ -e playlist ]; then
echo "Found a playlist. Here we go:"
interactive
else
echo "Error. No playlist found. No"
exit 1
fi
fi
|