Skip to content

Instantly share code, notes, and snippets.

@ecerulm
Created August 2, 2010 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecerulm/504258 to your computer and use it in GitHub Desktop.
Save ecerulm/504258 to your computer and use it in GitHub Desktop.
#!/bin/bash
ext=$1
if [ ! $ext ]; then
ext="avi"
fi
FILES=`find . -iname "*.$ext" -printf "%p\n"`
IFS="
"
for i in $FILES; do
dirname=`dirname $i`
g=`echo $i|perl -e '<STDIN> =~ m/S\d?(\d)E(\d+)/i; $1 and print $1 . "x" . $2'`
if [ ! $g ]; then
g=`echo $i|perl -e '<STDIN> =~ m/(\d)x(\d\d)/i; $1 and print $1 . "x" . $2'`
fi
if [ ! $g ]; then
g=`echo $i|perl -e '<STDIN> =~ m/(\d)(\d\d)/i; $1 and print $1 . "x" . $2;'`
fi
if [ ! $g ]; then
g=`echo $i|perl -e '<STDIN> =~ m/(\d\d)/i; $1 and print "1x" . $1'`
fi
if [ $g ]; then
g="$dirname/$g.$ext"
if [[ "$g" != "$i" ]]; then
echo "if [ ! -e \"$g\" ]; then mv \"$i\" \"$g\"; fi"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment