Ticket #11139: removecommercials

File removecommercials, 2.7 KB (added by celpa.firl@…, 8 years ago)

the userjob that removes the commercials

Line 
1#!/bin/sh
2PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin
3
4VIDEODIR=$1
5FILENAME=$2
6CHANID=$3
7STARTTIME=$4
8#exec > /tmp/removeCommercials$CHANID$STARTTIME
9
10
11echo "$CHANID $STARTTIME $FILENAME $VIDEODIR"
12# Sanity checking, to make sure everything is in order.
13if [ -z "$VIDEODIR" -o -z "$FILENAME" ]; then
14        echo "Usage: $0 <VideoDirectory> <FileName>"
15        exit 5
16fi
17if [ ! -f "$VIDEODIR/$FILENAME" ]; then
18        echo "File does not exist: $VIDEODIR/$FILENAME"
19        exit 6
20fi
21# The meat of the script. Flag commercials, copy the flagged commercials to
22# the cutlist, and transcode the video to remove the commercials from the
23# file.
24mythcommflag -f $VIDEODIR/$FILENAME 
25echo "fin1"
26ERROR=$?
27if [ $ERROR -gt 126 ]; then
28        echo "Commercial flagging failed for ${FILENAME} with error $ERROR" 
29        exit $ERROR
30fi
31echo "cutting"
32mythutil --gencutlist --chanid $CHANID --starttime $STARTTIME -f $VIDEODIR/$FILENAME
33ERROR=$?
34echo "cut'ed end"
35if [ $ERROR -ne 0 ]; then
36        echo "Copying cutlist failed for $FILENAME $CHANID $STARTTIME with error $ERROR"
37        exit $ERROR
38fi
39echo "transcodin"
40mythtranscode --verbose all --nodblog --loglevel debug --logpath /tmp -p def --honorcutlist --showprogress -i $VIDEODIR/$FILENAME -o $VIDEODIR/$FILENAME.tmp
41ERROR=$?
42echo "transcodid end "
43if [ $ERROR -ne 0 ]; then
44        echo "Transcoding failed for ${FILENAME} with error $ERROR"
45        exit $ERROR
46fi
47echo "cleaning up"
48mv $VIDEODIR/$FILENAME $VIDEODIR/$FILENAME.old
49mv $VIDEODIR/$FILENAME.tmp $VIDEODIR/$FILENAME
50rm $VIDEODIR/$FILENAME.old
51
52mythcommflag -f $VIDEODIR/${FILENAME} --rebuild 
53ERROR=$?
54if [ $ERROR -ne 0 ]; then
55        echo "Rebuilding seek list failed for ${FILENAME} with error $ERROR"
56        exit $ERROR
57fi
58mythutil --clearcutlist --chanid $CHANID --starttime $STARTTIME
59ERROR=$?
60echo "cutlist cleared"
61
62if [ $ERROR -eq 0 ]; then
63echo "cutlist cleared properly"
64        # Fix the database entry for the file
65        cat << EOF | mysql mythconverg
66UPDATE
67        recorded
68SET
69        cutlist = 0,
70        filesize = $(ls -l $VIDEODIR/$FILENAME | awk '{print $5}')
71WHERE
72        basename = '$FILENAME';
73
74EOF
75
76
77echo "cleared in db"
78
79cat << EOF | mysql mythconverg
80
81DELETE FROM
82       recordedmarkup
83WHERE
84       CONCAT( chanid, starttime ) IN (
85               SELECT
86                       CONCAT( chanid, starttime )
87               FROM
88                       recorded
89               WHERE
90                       basename = '$FILENAME'
91      );
92
93EOF
94        exit 0
95else
96        echo "Clearing cutlist failed for ${FILENAME} with error $ERROR" 
97        rm -f $VIDEODIR/$FILENAME.tmp
98        exit $ERROR
99fi
100
101
102