Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
init-script for streamripper
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
slick
Bodhisattva
Bodhisattva


Joined: 20 Apr 2003
Posts: 3495

PostPosted: Sat Aug 02, 2003 12:11 pm    Post subject: init-script for streamripper Reply with quote

my /etc/init.d/streamripper
not the best, but works fine

Code:

#!/sbin/runscript

PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"

depend() {
        need net
}

#---

# playlist to load, lock at http://yp.shoutcast.com/
playlist=http://yp.shoutcast.com/sbin/shoutcast-playlist.pls?rn=662\&file=filename.pls

# directory where store mp3s
destination=/data/streamripper/

# extra options
options="-r 10000 -z -o -u \"XMMS/1.x\""

# bitrate, only to verify stream
bitrate=128

#---

tmpdir=/tmp/.streamripper
tmpfile=$tmpdir/streamcheck.tmp
listfile=$tmpdir/playlist.tmp
runfile=/var/run/streamripper


start() {
        ebegin "Loading Streamripper"

        if [ -e $tmpdir ]; then
                rm -rf $tmpdir >& /dev/null
        fi
        mkdir $tmpdir

        ebegin "\t Download Playlist"

        lynx --source $playlist >& $listfile
        if [ "`cat $listfile | grep -E -i 'File(.*?)='`" = "" ] ; then
                eerror "\t Error while downloading playlist"
                return 1
        fi

        if [ "`cat $listfile | grep -E -i '[playlist]'`" = "" ] ; then
                eerror "\t Error while downloading playlist"
                return 1
        fi

        if [ "`cat $listfile | grep -E -i 'NumberOfEntries='`" = "" ] ; then
                eerror "\t Error while downloading playlist"
                return 1
        fi

        entries=`sed 's/\r//g' $listfile | grep -E -i 'NumberOfEntries=' | sed 's/NumberOfEntries=//ig'`
        ebegin "\t\t -> $entries streams"

        for stream in `sed 's/\r//g' $listfile | grep -E -i 'file(.*?)=' | cut -d '=' -f 2`; do
                ebegin "\t Checking stream $stream"
                streamripper $stream -d $tmpdir -o -u "XMMS/1.x" -l 10 >& $tmpfile
                if [ "`grep 'stream:' $tmpfile`" != "" ]; then
                        if [ "`grep \"bitrate: $bitrate\" $tmpfile`" != "" ]; then
                                if [ "$streamok" != "" ] ; then
                                        if [ $RANDOM -lt $RANDOM ] ; then
                                                streamok=$stream
                                        fi
                                else
                                        streamok=$stream
                                fi
                                ebegin "\t\t -> OK"
                        else
                                ewarn "\t\t -> not $bitrate bit"
                        fi
                else
                                ewarn "\t\t -> not available"
                fi
        done

        if [ -e $okfile ]; then
                stream=$streamok
                ebegin "Starting Streamripper on stream $stream"
                streamripper $stream -d $destination $options >& /dev/null &
                ps aux | grep "streamripper $stream -d $destination" | perl -pi -e 's/.*?([0-9].*).*?/$1/' | cut -d " " -f 1 > $runfile
        else
                eerror "There is not a working stream in $bitrate bit... :-("
                return 1
        fi

        if [ -e $tmpdir ]; then
                rm -rf $tmpdir >& /dev/null
        fi

        eend $?
}

stop() {
        ebegin "Stopping Streamripper"
        for pid in `cat $runfile` ; do
                kill $pid >& /dev/null ;
        done
        rm -f $runfile >& /dev/null
        eend $?
}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum