#!/bin/sh
source /etc/conf.d/vdr

NOAD="/usr/bin/noad"
NOADOPTS="--ac3 --overlap --jumplogo --comments"
# before opts
NOADBOPTS="--statisticfile=/var/log/noadonlinestat"
# after opts
NOADAOPTS="--background --backupmarks --statisticfile=/var/log/noadstat --OSD"

if [ -s $NOAD ] && [ "$SET_MARKS" != "Nie" ] ; then
   if [ "$SET_MARKS" = "Live" ] ; then
      NOADOPTS="$NOADOPTS --online=1"
   else
      if [ "$SET_MARKS" = "Immer" ] ; then
         NOADOPTS="$NOADOPTS --online=2"
      fi
   fi
else
   NOAD=""
fi

case "$1" in
   before)
      echo "$1 recording $2"
      if [ "$NOAD" != "" ] ; then
         CMD="$NOAD $NOADOPTS $NOADBOPTS before $2"
         logger -s "Starting <$CMD>"
         echo "$CMD" | at now
      fi
      if [ "$SHAREMARKS" = "1" ] ; then
         echo "marks2pts $1 '$2'" | at now
      fi
      ;;
   after)
      echo "$1 recording $2"
      if [ "$NOAD" != "" ] ; then
         CMD="$NOAD $NOADOPTS $NOADAOPTS nice $2"
         logger -s "Starting <$CMD>"
         echo "$CMD" | at now
      fi
      ;;
   edited)
      echo "$1 recording $2"
      if [ "$SHAREMARKS" = "1" ] ; then
         echo "marks2pts -upload $1 '$2'" | at now
      fi
      ;;
   *)
      echo "ERROR: unknown state: $1"
      ;;
esac
