#!/bin/sh

MAINDIR="/home/cds/audio/komik/U-Punkt"

GetDay () {
   case $1 in
       1) DAY="mo"
#          unset DAY ## Herbert Knebel ist nicht so toll ...
#          AUTHOR="HerbertKnebel"
          AUTHOR="UrbanPriol"
	  ;;
       2) DAY="di"
          ## Volker hat aufgehört ... ="di"
          AUTHOR="VolkerPispers"
	  ;;
       3) unset DAY
          AUTHOR="Mittwoch"
	  ;;
       4) DAY="do"
          AUTHOR="DieterNuhr"
	  ;;
       5) unset DAY
          AUTHOR="Freitag"
	  ;;
       6) DAY="sa"
          AUTHOR="GerburgJahnke"
	  ;;
       0) DAY="so"
          AUTHOR="EckehartVonHirschhausen"
	  ;;
       *) unset DAY
          unset AUTHOR
	  ;;
   esac
   WOY=`date +%Y%W`
}

# set -x
TODAY=`date +%w`
PREFILE=`date +%Y%W`
i=0

while [ $i -le $TODAY ] ; do
# while [ $i -le 7 ] ; do
   GetDay $i

   if [ -z $DAY ] ; then
     echo "$AUTHOR ist Blödsinn"
#     exit
   else
     FILE=${MAINDIR}/${AUTHOR}/${PREFILE}.ogg
     RPSRC="pnm://ras02.wdr.de/radio/wdr2/u-punkt/u-punkt-${DAY}/u-punkt-${DAY}.rm"
     if [ ! -f $FILE ] ; then
       /usr/local/bin/v_recordplay ${RPSRC}
       WAV=${MAINDIR}/${AUTHOR}/${PREFILE}.wav
#       if [ ${DAY} == "di" -o ${DAY} == "do" ] ; then
# Volker Pispers macht keinen U-Punkt mehr ... 
       if [ ${DAY} == "do" ] ; then
          audacity /tmp/v_recordplay.wav
       else
          mv /tmp/v_recordplay.wav /tmp/tmp.wav
       fi
       mv /tmp/tmp.wav ${WAV}
       oggenc ${WAV}
       mv "$WAV" /tmp/tmp.wav
       sox /tmp/tmp.wav -r 44100 -c2 "$WAV"
#       rm /tmp/tmp.wav
#       rm -f ${MAINDIR}/${AUTHOR}/${PREFILE}.wav
     fi
   fi

   i=$(($i+1))
done
