#!/usr/bin/env bash
# procatcher.sh v0.1 filipp

usage="$(basename $0) source dvd_volume"
  
if [ $# -eq 0 ]
	then echo "Usage: $usage";
	exit 1
fi

SRCDIR=$1; MOVIE=$2

cd "$SRCDIR"

echo "* Multiplexing audio and video..." 
mplex -f 8 *.m2v *.mp2 -o $MOVIE.mpg > /dev/null 2>&1

echo "* Extracting subtitles..."
/usr/local/bin/pxsup2dast *.sup* > /dev/null 2>&1

echo "* Multiplexing subtitles"
spumux *.d/spumux.xml < $MOVIE.mpg > $MOVIE.subbed.mpg

echo "* Creating dvdauthor project..."
cat > $MOVIE.xml <<EOS
<dvdauthor>
  <vmgm />
  <titleset>
    <titles>
      <pgc>
        <pre>subtitle=64;</pre>
        <vob file="$MOVIE.subbed.mpg" />
      </pgc>
    </titles>
  </titleset>
</dvdauthor>
EOS

echo "* Authoring DVD structure..."
dvdauthor -o $MOVIE -x $MOVIE.xml

echo "* Creating DVD image..."
mkisofs -dvd-video -V $MOVIE -o $MOVIE.iso $MOVIE > /dev/null 2>&1

echo "* Cleaning up..."
rm $MOVIE.mpg $MOVIE.subbed.mpg $MOVIE.xml
