From 74fc03031d5af312a1459cafaea2297e9b54824f Mon Sep 17 00:00:00 2001 From: Penny Leach Date: Tue, 26 Jan 2010 17:03:53 +1300 Subject: [PATCH] hacky perl script to rename all the crappy media that comes in --- bin/renametv.pl | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 bin/renametv.pl diff --git a/bin/renametv.pl b/bin/renametv.pl new file mode 100755 index 0000000..fb336c9 --- /dev/null +++ b/bin/renametv.pl @@ -0,0 +1,72 @@ +#!/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 = ; + +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; + -- 2.39.5