Archiv für den Monat: November 2012

Verschiedene Webradios nach x Tagen durchwechseln

Da ich gerne auch lokal die Musik habe, die auf dem von mir gekauften Radiostream läuft lass ich ein Skript laufen, dass nach 2 Tagen rippen zur nächsten Station wechselt und wiederum 2 Tage rippt. Sind alle Stationen durch wird von vorne begonnen. Wird dem Skript als Argument eines der Stichworte für ein bestimmtes Radio übergeben, fängt das rippen bei diesem Radio an.

Hier das Skript:

<pre>#!/bin/bash
DI_FM_FOLDER=/path/to/folder

if [ ! -z "$1" ]; then
        STREAM_TO_PLAY=$1
fi

function startRipping {
        # kill the running streamripper
        killall streamripper
        # lets safe the unix epoch time when the recording starts
        # we use that for calculating how long the webradio recording is running
        STARTTIME=`date +%s`
        echo "currently ripping $1"
        $DI_FM_FOLDER/$1.sh
        # as long as the startdate is greater than the current date minus 2 days the stream is executed
        while true; do
                if [ ! $STARTTIME -ge $(date +%s -d "-2 days") ];then
                        break;
                fi
                sleep 1
        done
}

# if the for loop inside the while exits, it starts again at the beginning (aka endless loop)
while true; do
        # process all the streams 2 days each
        for i in liquid progressive techno minimal psychill chillout trance goa; do
                # if this script is started with an argument, the var $STREAM_TO_PLAY is not empty and it will start
                # the ripping cicle with that stream and skips the ones before it. if it's started at the right point
                # it will set the $STREAM_TO_PLAY far to a empty string and normal ripping can proceed.
                if [ ! -z $STREAM_TO_PLAY ]; then
                        if [ $i == $STREAM_TO_PLAY ];then
                                startRipping $i
                                unset STREAM_TO_PLAY
                        fi
                else
                        startRipping $i
                fi
        done
done</pre>

Im startRipping ist dann nur eine case Kontrollstruktur für jeden einzelnen Radiostream und die jeweilige Radio-IP.