#!/bin/bash # Check for command-line arg. ARGCOUNT=3 E_WRONGARGS=65 if [ $# -ne "$ARGCOUNT" ] then echo "Usage: `basename $0` stream length outfile" exit $E_WRONGARGS fi STREAM=$1 LENGTH=$2 OUTFILE=$3 STREAMCMD="streamripper $STREAM -s -A -a %d.ogg -l $LENGTH -m 600 --quiet 2>&1 | tail -1 | awk '{print $1}'" TIME=$(date +%Y-%m-%d_%H%M) #create a temp folder to put the capture files in TMPFOLDER="/var/tmp/airtime/rips/streamipper-$TIME" if [ ! -d "TMPFOLDER" ]; then mkdir -p $TMPFOLDER fi #Record the stream with streamripper. It is possible the stream is not available in which case streamripper #will giveup. So try a few times... streamripper http://host:8000/stream.ogg -s -A -a %d.ogg -l 22000 -m 600 nTrys=0 maxTrys=5 status="error" until [[ "$status" != error* ]] ; do echo "recording with command: streamripper $STREAM -s -A -a $TMPFOLDER/%d.ogg -l $LENGTH -m 600 --quiet" status=$(streamripper $STREAM -s -A -a $TMPFOLDER/%d.ogg -l $LENGTH -m 600 --quiet 2>&1 | grep error) nTrys=$(($nTrys + 1)) if [ $nTrys -gt $maxTrys ] ; then echo "Number of re-trys exceeded. Quitting" exit fi if [[ "$status" == error* ]] ; then echo "$status retry $nTrys" sleep 5 fi done #At this point we have one or more files in the XXX folder which we need to merge with sox #Get rid of any empty files, sox can't handle them /usr/bin/find $TMPFOLDER/ -type f -size 0 -delete /usr/bin/sox $TMPFOLDER/*.ogg -t ogg -C6 $OUTFILE echo "merging files with command: /usr/bin/sox $TMPFOLDER/*.ogg $OUTFILE" # then we should be done! # you will probably to delete something # uncomment this when you've tested everything #rm $TMPFOLDER/*.ogg #rmdir $TMPFOLDER