#!/bin/sh
set -x
PRIO=15
TRANSCODE=transcode
MKISOFS=mkisofs
DVDAUTHOR=dvdauthor
DVDBACKUP=dvdbackup
DVD_DEVICE=/dev/hdb
DVD_BACKUP_TARGET=/film/dvdbackup
DVD_TITLE=1

[ -z "$DVDTRANSCODEOPTS" ]     && DVDTRANSCODEOPTS="-I 3 -V -y mpeg -Z 720x576 -b 192"
[ -z "$DVDTRANSCODEBITRATE" ]  && DVDTRANSCODEBITRATE="15000000.0"
[ -z "$DVDTCMPLEXOPTS" ]       && DVDTCMPLEXOPTS="-m d"
[ -z "$DVDMKISOFSOPTS" ]       && DVDMKISOFSOPTS="-V VDR2DVD_`date +"%d-%m-%Y"`"

# Start Backup
$DVDBACKUP -v 99 -i $DVD_DEVICE -o $DVD_BACKUP_TARGET -t $DVD_TITLE

# Get Title
Titel=`$DVDBACKUP -i $DVD_DEVICE -I|head -n 4|tail -1|awk '{print $8}'`
mkdir -p ${DVD_BACKUP_TARGET}/${Titel}
nice -${PRIO} dvddirgen -o ${DVD_BACKUP_TARGET}/${Titel}
cd ${DVD_BACKUP_TARGET}/${Titel}
echo "`date +"%d-%m-%2Y %T"` : Session $0 start for DVD $Titel"
#for vob in VIDEO_TS/*.VOB
#do
## Alle files demultiplexen
#    echo "Get Video"
#    mpeg3cat -v0 ${vob} > ${vob}.m2v
#    echo "Get Audio 0"
#    mpeg3cat -a0 ${vob} > ${vob}.mpa0
#    echo "Get Audio 1"
#    mpeg3cat -a1 ${vob} > ${vob}.mpa1
#    echo "Get Audio 2"
#    mpeg3cat -a2 ${vob} > ${vob}.mpa2
#done

# Video Files requantisieren

# Files multiplexen

# DVD mit dvdauthor anlegen


#nice -${PRIO} $DVDAUTHOR -T -o $DVD_BACKUP_TARGET/$Titel 

#status=$?
#if [ $status -ne 0 ]
#then
#       echo "ERROR : $DVDAUTHOR -T mit returncode $status beendet"
#       # Cleaning
#       cd -
#       rm -rf $DVD_BACKUP_TARGET/$Titel
#       exit 1
#fi
#
#printf "`date +"%T"`\t: Start $NKISOFS\n" 
#nice -${PRIO} $MKISOFS $DVDMKISOFSOPTS -dvd-video -o ${Titel}.iso $DVD_BACKUP_TARGET/$Titel
#printf "`date +"%T"`\t: End $NKISOFS\n" 
#status=$?

