#!/bin/bash ##set your auto-add directory myBotDir1=/home/its/mov myBotDir2=/home/its/tv ##set the $fullpath variable (remove the trailing / if it exists if [ "${1: -1}" == "/" ]; then fullpath="${1%/}";else fullpath="$1";fi localpath="${fullpath##*/}" if [ "$localpath" == "" ]; then exit fi # Check if there are subdirs subdirs=`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|mkv)$"` 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 done else # 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|mkv)$"` 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 done fi