Movie Script to Combine & Clean

Come up with a useful post-processing script? Share it here!
Post Reply
BrandonG777
Jr. Member
Jr. Member
Posts: 79
Joined: February 9th, 2009, 5:21 pm
Location: Tulsa, OK

Movie Script to Combine & Clean

Post by BrandonG777 »

You probably recognize most of this as the work of tret, and someone else, Bubba, I think. I combined the two, adding some stuff to make it easier for XBMC to recognize movies and also wake and update my Plex/XBMC Mac Mini. Enjoy!

Code: Select all

#!/bin/sh
#
# combine_and_clean.sh
#

# ---------- User definable section
LIBRARY_PATH="/mnt/disk1/share/Movies/" #Define where files should be moved (Use full path)
FAILED_PATH="/mnt/disk1/share/nzb/unprocessed/" #Define where failed downloads should be moved (Use full path)
MIN_SIZE='102400k' #Files below this size will be deleted unless they match known types
COMBINE=1  # to combine or not to combine multi-file movies (will mess up subs)
XBMC_IP='10.0.0.100:3000' #XBMC Web Server address and port
XBMC_MAC='00:16:cb:a5:e5:b0' #XBMC Mac Address
# ---------- User definable section

echo ""
echo "- combine_and_clean v1.0 by BrandonG777"
echo ""

# Search $1 (source path) for folders including _FAILED_, move contents of $1 to $FAILED_PATH if found and exit script
FAILED_TEST=`find "$1" -type d \( -iname "*_FAILED_*" \) -print`
if [ "$FAILED_TEST" ] ; then
echo "failed download detected, movie_clean aborted"
mv "$1" $FAILED_PATH
exit
fi

set -u
TMP="/tmp/sabtmp.out"

echo ""
echo "- the following junk files and empty directories were removed:"
# Remove small files except for those defined "-not", remove defined files
find "$1" -type f -not \( -iname "*video_ts*" -o -iname "*vts_*" -o -iname "*.nfo" -o -iname "*.jpg"  -o -iname "*.srt" -o -iname "*.sub" -o -iname "*.idx" \) -a \( -iname "*par2*" -o -iname "*sample*" -o -size -$MIN_SIZE \) -print -exec rm -rf {} \;
# Remove any empty directories
find "$1" -depth -type d -empty -print -exec rmdir {} \;

cd "$1"
 
# remove movie sample files (anything under 30MB)
if [ `find . -size -30000000c -regex '.*/.*\.avi' | wc -l` -eq 1 ]
        then 
        FILE3="$1`find . -size -30000000c -regex '.*/.*\.avi' | sed 's/^\.//'`"
        echo "Removing Sample: ${FILE3}"
        rm -f "${FILE3}"
 
fi
 
# combine 2 CD movies into 1 file (this will break subs)
if [ "${COMBINE}" = "1" ]; then
    if [ `find . -size +629145600c -regex '.*/.*\.avi' | wc -l` -eq 2 ]
                then
                FILE1="$1`find . -size +629145600c -regex '.*/.*\.avi' | sort | sed -n '1p' | sed 's/^\.//'`"
                FILE2="$1`find . -size +629145600c -regex '.*/.*\.avi' | sort | sed -n '2p' | sed 's/^\.//'`"
                echo "Joining Files ${FILE1} and ${FILE2} ..."
                avimerge -i "${FILE1}" "${FILE2}" -o "$1/$3".avi 2> /dev/null 1> /dev/null
                #mencoder -msglevel all=3 -forceidx -ovc copy -oac copy -o "$1/$3".avi "${FILE1}" "${FILE2}"
                echo "Removing Files ${FILE1} and ${FILE2} ..." 
                rm -f "${FILE1}"
                rm -f "${FILE2}"
   fi
fi

# Rename the largest avi to $3.avi
if [ `find . -regex '.*/.*\.avi' | wc -l` -eq 1 ]; then
	 echo ""
	 echo "- Renaming largest avi to ${3}.avi"
	 MOVIE="$1`find . -size +629145600c -regex '.*/.*\.avi' | sort | sed -n '1p' | sed 's/^\.//'`"
	 if [ -f "$3".avi ];then
			 echo "${3}.avi already named correctly."
	 else
			 mv "$MOVIE" "$3".avi
	 fi
fi

echo ""
echo "- $3 has been moved to $LIBRARY_PATH"
# move processed movies to LIBRARY_PATH
mv "$1" $LIBRARY_PATH

## Generate AppleTV/ATVFiles XML file for movie & download cover
#atv2xml.pl -usedir -usefirst -overwrite -duration -altimg "$1/$3" > $TMP
#cat $TMP
 
## Change perms on directory
#chmod -R 777 "$LIBRARY_PATH"
 
#cat $TMP | growlnotify.pl
#rm -f $TMP

echo ""
echo "- post processing complete, video library update request sent to XBMC/Plex"
# Wake the XBMC/Plex machine from sleep
wakeonlan $XBMC_MAC > /dev/null
sleep 5
wakeonlan $XBMC_MAC > /dev/null
# access the xbmc web interface and trigger a video library update
wget --delete-after 'http://'$XBMC_IP'/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)' >/dev/null 2>&1
Uncomment the stuff for AppleTV and Growl if you like, though it's unverified it should work.
tret
Full Member
Full Member
Posts: 148
Joined: August 2nd, 2008, 2:07 pm

Re: Movie Script to Combine & Clean

Post by tret »

Good Stuff Brandon, Nice to see some of my work coming in handy :)

The main reason for the removal of junk files and empty directories portion of my script was to address sample files, I see that you added a sample file removal section. This is a little redundant, were you finding that sample files weren't being removed?

Good work, I'll have to work the combining features into my own stuff. Thanks for sharing!

tret
Post Reply