#!/bin/bash # mount external drive (must be in /etc/fstab) mount /media/ext # specify the base directory to move to fs="/media/ext/TV/" # specify the base directory to search base="/torrents/finished/" for file in `find "$base" | replace " " "~" | grep avi`; do file=`echo $file | replace "~" " "` show=`basename "$file" | grep -io "[^\/]*S[0-9]\{1,2\}" | grep -io ".*[\._ -]" | replace "." " " "_" " " "-" " " ` while [ -n "`echo "$show" | grep \" \{2\}\"`" ]; do show=`echo "$show" | replace " " " "` done show=`echo "\`expr "$show" : '[ ]*\(.*\)[ *]$'\`"` #echo "\"$show\"" snum=`basename "$file" | grep -io "S[0-9]\{1,2\}" | grep -io "[1-9]\?[1-9]"` season="Season $snum" #echo $season show=`ls "$fs" | grep -io "$show"` #echo "DIR: \"$show\"" dest=$fs if [ -d "$fs/$show/$season/" ]; then dest="$fs/$show/$season/" else if [ -d "$fs/$show/Season$snum" ]; then dest="$fs/$show/Season$snum/" else if [ -d "$fs/$show/" ]; then dest="" fi fi fi if [ "$dest" != "" ]; then #echo "mv -v \"$file\" \"$dest\"" mv -v "$file" "$dest" wait `pidof mv` fi done # Delete all .nfo, .srt, .txt files find "$base" -name *.nfo -exec rm {} \; find "$base" -name *.srt -exec rm {} \; find "$base" -name *.txt -exec rm {} \; # Delete all empty folders (recursively) find "$base" -depth -mindepth 1 -type d -empty -exec rmdir {} \; umount /media/ext exit 0;