#!/usr/bin/perl -l use LWP::Simple; use Getopt::Std; getopts("ns"); $no_act = $opt_n; $output_shellscript = $opt_s; sub nosquo($) { for ($_[0]) { s/'/'\\''/g; return $_ } } @ARGV = (<$ARGV[0]>) if (@ARGV == 1 && $ARGV[0] =~ m/[*?]/); # windows die unless @ARGV; for (@ARGV) { $old_filename = $_; y/./ /; ($show, $season, $epinum, $ext) = m/(.*) s?(\d+)[ex](\d+) (?:.+ )?(...)$/i or warn, next; $url = "http://www.tvrage.com/quickinfo.php?show=$show&ep=${season}x$epinum"; @info = split /\n/, get $url or warn, next; my ($show_name, @f); for (@info) { $show_name = $1 if m/^Show Name@(.*)/; @f = split /[@^]/ if m/^Episode Info@/; } ($season, $epinum) = split /x/, $f[1]; warn, next unless $show_name && @f > 2; #$new_filename = join(' ', $show_name, @f[1,2]) . ".$ext"; $new_filename = "$show_name - S${season}E${epinum} - $f[2].$ext"; $new_filename =~ y/\ /:"<>*?|/;'()___/; # windows if ($output_shellscript) { printf "mv '%s' '%s';\n", nosquo $old_filename, nosquo $new_filename; } elsif (!$no_act) { rename $old_filename, $new_filename or warn "$!\n"; } }