#!/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