--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use Getopt::Long;
+use File::Copy;
+use Cwd;
+
+my $filenames = {};
+my $inputdir = getcwd;
+my $somethingtodo = 0;
+
+my @usualsuspects = qw/
+ xvid xor ffndvd repack preair aaf 720p x264 dimension dvdrip
+ hdtv 0tv fqm 2hd notv ws pdtv lol vtv xii dvdscr sys fov dot
+ vostfr p0w4
+/;
+
+GetOptions(
+ 'inputdir=s', \$inputdir,
+);
+
+die "Target directory $inputdir was non empty" unless (<$inputdir/*>);
+
+while (<$inputdir/*>) {
+ my $current = $_;
+ tr/[A-Z]/[a-z]/;
+ s/s(\d+)\.?e(\d+)/$1$2/g;
+ s/ - /./g;
+ s/ /_/g;
+ s/'//g;
+ s/-/_/g;
+ s/[\[\]]//g;
+ s/[S|s]?(\d+)\.?[E|e|x|X]?(\d+)/$1$2/;
+ s/\.0/./g;
+ foreach my $bad (@usualsuspects) {
+ s/(\[|\.|_|-)?$bad(\]|-)?//g;
+ }
+ if (/^(.*\/(?!.*\/))([a-z_.]*)((?:_|\.)[0-9]*)(?:_|\.)+([a-z_.,&]*)$/) {
+ my ($path, $series, $epno, $title) = ($1, $2, $3, $4);
+ $series =~ s/(_|\.)//g;
+ $epno =~ s/.(.*)/$1/g;
+ $title =~ s/\./_/g;
+ $title =~ s/_(avi|mkv|mov|srt)/.$1/;
+ if ($epno =~ /^\d$/) {
+ $epno = "0$epno";
+ }
+ $_ = $path . $series . '.' . $epno . '.' . $title;
+ }
+ next if $current eq $_;
+ $filenames->{$current} = $_;
+ print "$current becomes $_\n";
+ $somethingtodo = 1;
+}
+
+unless ($somethingtodo) { print "Nothing to do!\n"; exit 0; }
+
+print "do you want to continue? [Y/n]";
+my $answer = <STDIN>;
+
+chomp $answer;
+
+if ($answer eq 'Y' || $answer eq 'y' || $answer eq '') {
+ print 'Moving ...';
+ foreach my $key (keys %$filenames) {
+ move($key, $filenames->{$key});
+ }
+ print "Done\n";
+}
+
+exit 0;
+