Difference between revisions of "Script - commercialremover"
(Removed mapping files, added a missing "then" to the script) |
|||
(14 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
This script was started based upon the old [[script_-_RemoveCommercials|script]], which was needed as part of the [http://sourceforge.net/projects/mythgrid/ MythGrid] plugin development. It was necessary to change it so significantly to get the required behavior, that it seemed cleaner to post it as a new script. | This script was started based upon the old [[script_-_RemoveCommercials|script]], which was needed as part of the [http://sourceforge.net/projects/mythgrid/ MythGrid] plugin development. It was necessary to change it so significantly to get the required behavior, that it seemed cleaner to post it as a new script. | ||
− | {{Warning box|This behavior is not supported within the mythutil/mythtranscode programs themselves as the commercial detector is not considered sufficiently accurate to permanently remove sections of video without a manual confirmation.}} | + | {{Warning box|This behavior is not supported within the mythutil/mythtranscode programs themselves as the commercial detector is not considered sufficiently accurate to permanently remove sections of video without a manual confirmation. Original copies of the file will be stored with the .old extension, so you may want to delete them periodically, or just comment out the mv line below.}} |
Line 9: | Line 9: | ||
commercialremover.sh %DIR% %FILE% %CHANID% %STARTTIMEUTC% | commercialremover.sh %DIR% %FILE% %CHANID% %STARTTIMEUTC% | ||
− | {{Note box| | + | {{Note box|This script attempts to acquire database configuration from ''/etc/mythtv/mysql.txt'', ''/etc/mythtv/config.xml'', and then ''~/.mythtv/config.xml'' using whichever it finds first. If none are found or cannot be read, the script will not update the database to reflect the new file size, but the commercials have already been removed. |
+ | |||
+ | Also, if interested in creating logs be sure the user can edit ''/tmp/'' folder.}} | ||
Line 17: | Line 19: | ||
{{Code box|commercialremover.sh| | {{Code box|commercialremover.sh| | ||
<pre> | <pre> | ||
− | + | ##### commercialremover.sh Script for MythTV, updated 2013/12/15 | |
− | |||
− | ##### commercialremover.sh Script for MythTV, updated 2013/ | ||
### | ### | ||
## Made for MythTV 0.26 also tested against 0.27, by jmw for MythGrid | ## Made for MythTV 0.26 also tested against 0.27, by jmw for MythGrid | ||
Line 48: | Line 48: | ||
INFILEPATH="$VIDEODIR/$FILENAME" | INFILEPATH="$VIDEODIR/$FILENAME" | ||
TEMPFILEPATH="$INFILEPATH.tmp" | TEMPFILEPATH="$INFILEPATH.tmp" | ||
+ | MAPEXT=".map" | ||
− | |||
LOGFOLDERPATH="/tmp/mythtv/commercialRemoval" | LOGFOLDERPATH="/tmp/mythtv/commercialRemoval" | ||
if [ ! -d "$LOGFOLDERPATH" ]; then | if [ ! -d "$LOGFOLDERPATH" ]; then | ||
Line 72: | Line 72: | ||
exit $ERROR | exit $ERROR | ||
fi | fi | ||
+ | |||
+ | #Save a copy of the original with the extension .old | ||
+ | #mv -f $INFILEPATH $INFILEPATH.old | ||
#Overwrite the original file with the transcoded file | #Overwrite the original file with the transcoded file | ||
mv -f $TEMPFILEPATH $INFILEPATH | mv -f $TEMPFILEPATH $INFILEPATH | ||
+ | #Sometimes a .map file is generated, clean that up too | ||
+ | rm -f $TEMPFILEPATH$MAPEXT | ||
#clear out the old cutlist | #clear out the old cutlist | ||
Line 86: | Line 91: | ||
UPDATEDFILESIZE=$(du -b $INFILEPATH | awk '{print $1}') | UPDATEDFILESIZE=$(du -b $INFILEPATH | awk '{print $1}') | ||
− | #Get mythtv database information | + | #Get mythtv database information |
− | DBSERVER= | + | DBSERVER="" |
− | DBUSER= | + | DBUSER="" |
− | DBNAME= | + | DBNAME="" |
− | + | DBPASS="" | |
− | DBPASS= | ||
− | # | + | #Try getting mythtv database information from existant files in the following order |
− | + | MYTHDBFILE="/etc/mythtv/mysql.txt" | |
+ | MYTHCONFIGFILE="/etc/mythtv/config.xml" | ||
+ | MYCONFIGFILE="~/.mythtv/config.xml" | ||
− | echo "Commericals removed for $FILENAME" | + | if [ -f "$MYTHDBFILE" ]; then |
+ | DBSERVER=$( grep "DBHostName=" $MYTHDBFILE | sed s/.*DBHostName=/\/ ) | ||
+ | DBUSER=$( grep "DBUserName=" $MYTHDBFILE | sed s/.*DBUserName=/\/ ) | ||
+ | DBNAME=$( grep "DBName=" $MYTHDBFILE | sed s/.*DBName=/\/ ) | ||
+ | # Determine database password | ||
+ | DBPASS=$( grep "DBPassword=" $MYTHDBFILE | sed s/.*DBPassword=/\/ ) | ||
+ | elif [ -f "$MYTHCONFIGFILE" ]; then | ||
+ | DBSERVER=$( grep -E -m 1 -o "<DBHostName>(.*)</DBHostName>" $MYTHCONFIGFILE | sed -e 's,.*<DBHostName>\([^<]*\)</DBHostName>.*,\1,g' ) | ||
+ | DBUSER=$( grep -E -m 1 -o "<DBUserName>(.*)</DBUserName>" $MYTHCONFIGFILE | sed -e 's,.*<DBUserName>\([^<]*\)</DBUserName>.*,\1,g' ) | ||
+ | DBNAME=$( grep -E -m 1 -o "<DBName>(.*)</DBName>" $MYTHCONFIGFILE | sed -e 's,.*<DBName>\([^<]*\)</DBName>.*,\1,g' ) | ||
+ | DBPASS=$( grep -E -m 1 -o "<DBPassword>(.*)</DBPassword>" $MYTHCONFIGFILE | sed -e 's,.*<DBPassword>\([^<]*\)</DBPassword>.*,\1,g' ) | ||
+ | elif [ -f "$MYCONFIGFILE" ]; then | ||
+ | DBSERVER=$( grep -E -m 1 -o "<Host>(.*)</Host>" $MYCONFIGFILE | sed -e 's,.*<Host>\([^<]*\)</Host>.*,\1,g' ) | ||
+ | DBUSER=$( grep -E -m 1 -o "<UserName>(.*)</UserName>" $MYCONFIGFILE | sed -e 's,.*<UserName>\([^<]*\)</UserName>.*,\1,g' ) | ||
+ | DBNAME=$( grep -E -m 1 -o "<DatabaseName>(.*)</DatabaseName>" $MYCONFIGFILE | sed -e 's,.*<DatabaseName>\([^<]*\)</DatabaseName>.*,\1,g' ) | ||
+ | DBPASS=$( grep -E -m 1 -o "<Password>(.*)</Password>" $MYCONFIGFILE | sed -e 's,.*<Password>\([^<]*\)</Password>.*,\1,g' ) | ||
+ | fi | ||
+ | |||
+ | if [ -z "$DBSERVER" -o -z "$DBUSER" -o -z "$DBPASS" -o -z "$DBNAME" ]; then | ||
+ | # Update the database entry for the file size | ||
+ | echo "UPDATE recorded SET filesize='${UPDATEDFILESIZE}' WHERE chanid='${CHAN}' && starttime='${START}'" | mysql -h ${DBSERVER} -u ${DBUSER} --password=${DBPASS} ${DBNAME} | ||
+ | fi | ||
+ | |||
+ | echo "Commericals removed for $FILENAME" >> $LOG 2>&1 | ||
exit 0 | exit 0 | ||
Line 102: | Line 131: | ||
}} | }} | ||
− | {| | + | {| width="100%" |
+ | |{{VersionNote|0.27|Works with 0.27}} | ||
+ | |[[http://sourceforge.net/projects/mythgrid/files/mythTV%20Related%20Scripts/commercialremover.sh/download Download commercialremover.sh]] | ||
+ | |[http://www.mythtv.org/wiki/index.php?title=Script_-_RemoveCommercials&action=watch Watch Article For Changes] | ||
|{{Webpage|https://sourceforge.net/projects/mythgrid/|MythGrid}} | |{{Webpage|https://sourceforge.net/projects/mythgrid/|MythGrid}} | ||
− | |||
− | |||
− | |||
|} | |} | ||
[[Category:User_Job_Scripts]] | [[Category:User_Job_Scripts]] | ||
[[Category:Transcode_Scripts]] | [[Category:Transcode_Scripts]] |
Latest revision as of 12:10, 15 December 2013
This script was started based upon the old script, which was needed as part of the MythGrid plugin development. It was necessary to change it so significantly to get the required behavior, that it seemed cleaner to post it as a new script.
Warning: This behavior is not supported within the mythutil/mythtranscode programs themselves as the commercial detector is not considered sufficiently accurate to permanently remove sections of video without a manual confirmation. Original copies of the file will be stored with the .old extension, so you may want to delete them periodically, or just comment out the mv line below.
In order to run the script as a user job, add the following command as a user job in your backend setup.
commercialremover.sh %DIR% %FILE% %CHANID% %STARTTIMEUTC%
Note: This script attempts to acquire database configuration from /etc/mythtv/mysql.txt, /etc/mythtv/config.xml, and then ~/.mythtv/config.xml using whichever it finds first. If none are found or cannot be read, the script will not update the database to reflect the new file size, but the commercials have already been removed.
Also, if interested in creating logs be sure the user can edit /tmp/ folder.
The following script can be setup as a User Job to automatically flag and remove commercials from a recording. This script code was updated 11/21/2013 to work with MythTV 0.27. It should still work with 0.26 as well.
##### commercialremover.sh Script for MythTV, updated 2013/12/15 ### ## Made for MythTV 0.26 also tested against 0.27, by jmw for MythGrid ## https://sourceforge.net/projects/mythgrid/ ## ## This script requires the User Job to pass additional arguments under MythTV 0.26 or higher ## User job command: ## ‘commercialremover.sh %DIR% %FILE% %CHANID% %STARTTIMEUTC%' ### ##### VIDEODIR=$1 FILENAME=$2 CHAN=$3 START=$4 # Sanity checking, to make sure everything is in order. Modified to check $CHAN and $START for MythTV 0.25 or higher support if [ -z "$VIDEODIR" -o -z "$FILENAME" -o -z "$CHAN" -o -z "$START" ]; then echo "Usage: $0 <VideoDirectory> <FileName>" exit 5 fi if [ ! -f "$VIDEODIR/$FILENAME" ]; then echo "File does not exist: $VIDEODIR/$FILENAME" exit 6 fi #create temp file name FILENAMEPREFIX="${CHAN}_${START}" INFILEPATH="$VIDEODIR/$FILENAME" TEMPFILEPATH="$INFILEPATH.tmp" MAPEXT=".map" LOGFOLDERPATH="/tmp/mythtv/commercialRemoval" if [ ! -d "$LOGFOLDERPATH" ]; then mkdir -p $LOGFOLDERPATH fi LOG="$LOGFOLDERPATH/${FILENAMEPREFIX}.log" echo "Generating cutlist..." mythutil -q --gencutlist --chanid $CHAN --starttime $START > /dev/null 2>&1 ERROR=$? if [ $ERROR -ne 0 ]; then echo "Generating cutlist failed for ${FILENAME} with error $ERROR" >> $LOG 2>&1 exit $ERROR fi echo "Transcoding..." mythtranscode --honorcutlist --allkeys -v all,jobqueue --showprogress --mpeg2 -i $INFILEPATH -o $TEMPFILEPATH > /dev/null 2>&1 ERROR=$? if [ $ERROR -ne 0 ]; then echo "Transcoding failed for ${FILENAME} with error $ERROR" >> $LOG 2>&1 exit $ERROR fi #Save a copy of the original with the extension .old #mv -f $INFILEPATH $INFILEPATH.old #Overwrite the original file with the transcoded file mv -f $TEMPFILEPATH $INFILEPATH #Sometimes a .map file is generated, clean that up too rm -f $TEMPFILEPATH$MAPEXT #clear out the old cutlist echo "Clearing cutlist..." mythutil -q --clearcutlist --chanid $CHAN --starttime $START > /dev/null 2>&1 echo "Clearing skiplist..." mythutil -q --clearskiplist --chanid $CHAN --starttime $START > /dev/null 2>&1 #Determine new filesize to update the db with UPDATEDFILESIZE=$(du -b $INFILEPATH | awk '{print $1}') #Get mythtv database information DBSERVER="" DBUSER="" DBNAME="" DBPASS="" #Try getting mythtv database information from existant files in the following order MYTHDBFILE="/etc/mythtv/mysql.txt" MYTHCONFIGFILE="/etc/mythtv/config.xml" MYCONFIGFILE="~/.mythtv/config.xml" if [ -f "$MYTHDBFILE" ]; then DBSERVER=$( grep "DBHostName=" $MYTHDBFILE | sed s/.*DBHostName=/\/ ) DBUSER=$( grep "DBUserName=" $MYTHDBFILE | sed s/.*DBUserName=/\/ ) DBNAME=$( grep "DBName=" $MYTHDBFILE | sed s/.*DBName=/\/ ) # Determine database password DBPASS=$( grep "DBPassword=" $MYTHDBFILE | sed s/.*DBPassword=/\/ ) elif [ -f "$MYTHCONFIGFILE" ]; then DBSERVER=$( grep -E -m 1 -o "<DBHostName>(.*)</DBHostName>" $MYTHCONFIGFILE | sed -e 's,.*<DBHostName>\([^<]*\)</DBHostName>.*,\1,g' ) DBUSER=$( grep -E -m 1 -o "<DBUserName>(.*)</DBUserName>" $MYTHCONFIGFILE | sed -e 's,.*<DBUserName>\([^<]*\)</DBUserName>.*,\1,g' ) DBNAME=$( grep -E -m 1 -o "<DBName>(.*)</DBName>" $MYTHCONFIGFILE | sed -e 's,.*<DBName>\([^<]*\)</DBName>.*,\1,g' ) DBPASS=$( grep -E -m 1 -o "<DBPassword>(.*)</DBPassword>" $MYTHCONFIGFILE | sed -e 's,.*<DBPassword>\([^<]*\)</DBPassword>.*,\1,g' ) elif [ -f "$MYCONFIGFILE" ]; then DBSERVER=$( grep -E -m 1 -o "<Host>(.*)</Host>" $MYCONFIGFILE | sed -e 's,.*<Host>\([^<]*\)</Host>.*,\1,g' ) DBUSER=$( grep -E -m 1 -o "<UserName>(.*)</UserName>" $MYCONFIGFILE | sed -e 's,.*<UserName>\([^<]*\)</UserName>.*,\1,g' ) DBNAME=$( grep -E -m 1 -o "<DatabaseName>(.*)</DatabaseName>" $MYCONFIGFILE | sed -e 's,.*<DatabaseName>\([^<]*\)</DatabaseName>.*,\1,g' ) DBPASS=$( grep -E -m 1 -o "<Password>(.*)</Password>" $MYCONFIGFILE | sed -e 's,.*<Password>\([^<]*\)</Password>.*,\1,g' ) fi if [ -z "$DBSERVER" -o -z "$DBUSER" -o -z "$DBPASS" -o -z "$DBNAME" ]; then # Update the database entry for the file size echo "UPDATE recorded SET filesize='${UPDATEDFILESIZE}' WHERE chanid='${CHAN}' && starttime='${START}'" | mysql -h ${DBSERVER} -u ${DBUSER} --password=${DBPASS} ${DBNAME} fi echo "Commericals removed for $FILENAME" >> $LOG 2>&1 exit 0
|
[Download commercialremover.sh] | Watch Article For Changes | - MythGrid |