#!/bin/bash##set your auto-add directorymyBotDir1=/home/its/movmyBotDir2=/home/its/tv##set the $fullpath variable (remove the trailing / if it existsif [ "${1: -1}" == "/" ]; then fullpath="${1%/}";else fullpath="$1";filocalpath="${fullpath##*/}"if [ "$localpath" == "" ]; then exitfi# Check if there are subdirssubdirs=`ls -1p $fullpath | egrep "[cC][dD][0-9]*/$"`if [ -n "$subdirs" ]; then # there are subdirs for dir in $subdirs; do had_rar="NO" # Check if there's a .rar hasrars=`ls -1 "$fullpath/$dir" | egrep ".rar$"` if [ -n "$hasrars" ]; then # stuff is in a .rar file, unpack here unrar e "$fullpath/$dir/*.rar" "$fullpath/$dir" > /dev/null had_rar="YES" fi # find the .avi files avis=`ls -1 "$fullpath/$dir" | egrep ".avi$"` for avi in $avis; do # check if they're samples sample=`echo "$avi" | egrep "[sS][aA][mM][pP][lL][eE]"` if [ -z "$sample" ]; then # not a sample, copy it over case $localpath in *720p*) echo "copying $fullpath/$dir/$avi to $myBotDir1/$localpath.${dir%/}${avi: -4}" cp "$fullpath/$dir/$avi" "$myBotDir1/$localpath.${dir%/}${avi: -4}" ;; *) echo "copying $fullpath/$dir/$avi to $myBotDir2/$localpath.${dir%/}${avi: -4}" cp "$fullpath/$dir/$avi" "$myBotDir2/$localpath.${dir%/}${avi: -4}" ;; esac if [ "$had_rar" == "YES" ]; then echo "deleting $fullpath/$dir/$avi" rm "$fullpath/$dir/$avi" fi fi done doneelse # there are no subdirs # Check if there's a .rar hasrars=`ls -1 $fullpath | egrep ".rar$"` if [ -n "$hasrars" ]; then # stuff is in a .rar file, unpack here unrar e "$fullpath/*.rar" "$fullpath" > /dev/null had_rar="YES" fi # find the .avi files avis=`ls -1 $fullpath | egrep ".avi$"` for avi in $avis; do # check if they're samples sample=`echo "$avi" | egrep "[sS][aA][mM][pP][lL][eE]"` if [ -z "$sample" ]; then # not a sample, copy it over case $localpath in *720p*) echo "copying $fullpath/$dir/$avi to $myBotDir1/$localpath.${dir%/}${avi: -4}" cp "$fullpath/$dir/$avi" "$myBotDir1/$localpath.${dir%/}${avi: -4}" ;; *) echo "copying $fullpath/$dir/$avi to $myBotDir2/$localpath.${dir%/}${avi: -4}" cp "$fullpath/$dir/$avi" "$myBotDir2/$localpath.${dir%/}${avi: -4}" ;; esac if [ -n "$had_rar" ]; then echo "deleting $fullpath/$avi" rm "$fullpath/$avi" fi fi donefi