Script - RemoveCommercials

From MythTV Official Wiki
Revision as of 08:06, 2 August 2006 by Zwhite (talk | contribs) (Initial version of a script to automatically remove commercials from a recording.)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The follow script can be setup as a User Job to automatically flag and remove commercials from a recording.

#!/bin/sh
# removecommercials.sh
#
# Copyright 2006 Zach White <zwhite-mythtv@darkstar.frop.org>
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
VIDEODIR=$1
FILENAME=$2
# Sanity checking, to make sure everything is in order.
if [ -z "$VIDEODIR" -o -z "$FILENAME" ]; then
        echo "Usage: $0 <VideoDirectory> <FileName>"
        exit 4
fi
if [ ! -f $VIDEODIR/$FILENAME ]; then
        echo "File does not exist: $VIDEODIR/$FILENAME"
        exit 5
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 -ne 2 ]; then
        echo "Commercial flagging failed for ${FILENAME} with error $ERROR"
        exit 1
fi
mythcommflag --gencutlist -f $VIDEODIR/$FILENAME
ERROR=$?
if [ $ERROR -ne 0 ]; then
        echo "Copying cutlist failed for ${FILENAME} with error $ERROR"
        exit 2
fi
mythtranscode --honorcutlist --showprogress -i $VIDEODIR/$FILENAME -o $VIDEODIR/$FILENAME.tmp
ERROR=$?
if [ $ERROR -eq 0 ]; then
        mv /usr/video/$FILENAME /usr/video/$FILENAME.old
        mv /usr/video/$FILENAME.tmp /usr/video/$FILENAME
        exit 0
else
        echo "Transcoding failed for ${FILENAME} with error $ERROR"
        rm /usr/video/$FILENAME.tmp
        exit 3
fi