#!/bin/bash
#
# shellrip.sh - Copyright (c) 2006 by Patrick Staehlin <me@packi.ch>
#
# Rips the vob's from a DVD in 1 GB chunks.
#
# Usage:
# ./shellrip.sh [tracknr] [target_dir]
#
# The default tracknr is the longest track on the disk.
# If you don't specify target_dir, the dîrectory will be the dvd's title.
#

lsdvd /dev/dvd > tmpout 2> /dev/null
title=`grep "Disc Title" tmpout | cut -c 13-`
trackToRip=`grep "Longest" tmpout | cut -c 16-`
rm tmpout

if [ "x$2" != "x" ]; then
  title=$2
fi

titleAbs=`pwd`/$title;

if [ "x$1" != "x" ]; then
  if [ $trackToRip = $1 ]; then
    mkdir $title;
    cd $title;
  else
    trackToRip=$1;
    mkdir $title;
    cd $title;
    mkdir $1;
    cd $1;
    titleAbs=$titleAbs/$1;
    title="$title-$1";
  fi
else
  mkdir $title;
  cd $title;
fi

echo "DVD: $title will rip $trackToRip";
dr_exec tccat -t dvd -T $trackToRip,-1,1 -i /dev/dvd 2> /dev/null | dr_splitpipe -f $titleAbs/nav.log 1024 $titleAbs/$title vob 2> /dev/null | tcextract -a 0 -x ac3 -t vob | tcdecode -x ac3 | tcscan -x pcm

