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¶meter=XBMC.updatelibrary(video)' >/dev/null 2>&1