Skip to content

Instantly share code, notes, and snippets.

@zombor
Created March 11, 2011 18:05
Show Gist options
  • Save zombor/866280 to your computer and use it in GitHub Desktop.
Save zombor/866280 to your computer and use it in GitHub Desktop.
#!/bin/sh
VIDEODIR=$1
FILENAME=$2
CHANID=$3
STARTTIME=$4
# Sanity checking, to make sure everything is in order.
if [ -z "$VIDEODIR" -o -z "$FILENAME" -o -z "$CHANID" -o -z "$STARTTIME" ]; then
echo "Usage: $0 <VideoDirectory> <FileName> <CHANID> <STARTTIME>"
fi
if [ ! -f "$VIDEODIR/$FILENAME" ]; then
echo "File does not exist: $VIDEODIR/$FILENAME"
exit 6
fi
# The meat of the script. Flag commercials, copy the flagged commercials to
# the cutlist, and transcode the video to remove the commercials from the
# file.
mythcommflag -f $VIDEODIR/$FILENAME
ERROR=$?
if [ $ERROR -gt 126 ]; then
echo "Commercial flagging failed for ${FILENAME} with error $ERROR"
exit $ERROR
fi
mythcommflag --gencutlist -f $VIDEODIR/$FILENAME
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "Copying cutlist failed for ${FILENAME} with error $ERROR"
exit $ERROR
fi
mythtranscode --honorcutlist --showprogress -c $CHANID -s $STARTTIME -o $VIDEODIR/$FILENAME.tmp
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "Transcoding failed for ${FILENAME} with error $ERROR"
exit $ERROR
fi
mv $VIDEODIR/$FILENAME $VIDEODIR/$FILENAME.old
mv $VIDEODIR/$FILENAME.tmp $VIDEODIR/$FILENAME
mythcommflag -f $VIDEODIR/${FILENAME} --rebuild
ERROR=$?
if [ $ERROR -ne 0 ]; then
echo "Rebuilding seek list failed for ${FILENAME} with error $ERROR"
exit $ERROR
fi
mythcommflag --clearcutlist -f $VIDEODIR/$FILENAME
ERROR=$?
if [ $ERROR -eq 0 ]; then
# Fix the database entry for the file
cat << EOF | mysql -u mythtv -pmythtv mythconverg
UPDATE
recorded
SET
cutlist = 0,
filesize = $(ls -l $VIDEODIR/$FILENAME | awk '{print $5}')
WHERE
basename = '$FILENAME';
EOF
exit 0
else
echo "Clearing cutlist failed for ${FILENAME} with error $ERROR"
rm -f $VIDEODIR/$FILENAME.tmp
exit $ERROR
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment