#! /bin/bash

# (C) Copyright Craig Sanders <cas@taz.net.au> 2009
#
# This script is licensed under the terms of the GNU General Public
# License version 3 (or later, at your option).

# This script is really ugly and amongst other faults, assumes that all
# myth recordings are in /video/myth?/ directories.  this works on my
# system.  you'll probably have to modify it on yours.
#
# worse, there's absolutely no error or input-sanity checking. and it's
# usable only by those who think shell scripts are self-documenting.

VID="$1"
CHST=$(echo $VID | sed -e 's/\.\(mpg\|nuv\).*//')

CHANNEL=$(echo $CHST | sed -e 's/_.*//')
STARTTIME=$(echo $CHST | sed -e 's/.*_//')

FNAME=$(find /video/myth?/ -name "$VID*" | head -1)
DIR=$(dirname $FNAME)

echo "$VID => $CHST => $CHANNEL => $STARTTIME"
echo "DIR=$DIR"

# cut out ads
echo mythtranscode -c $CHANNEL -s $STARTTIME --showprogress -l -m 
mythtranscode -c $CHANNEL -s $STARTTIME --showprogress -l -m 

# replace video with stripped copy
pushd $DIR
mv $VID $VID.bak
mv $VID.tmp $VID
popd

# rebuild index
echo mythtranscode -c $CHANNEL -s $STARTTIME --showprogress -b
mythtranscode -c $CHANNEL -s $STARTTIME --showprogress -b


