Skip to content

Instantly share code, notes, and snippets.

@jbarrett
Last active December 20, 2015 14:29
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 jbarrett/6147397 to your computer and use it in GitHub Desktop.
Save jbarrett/6147397 to your computer and use it in GitHub Desktop.
Quick and dirty script to rename DVD Rips, supplies the existing filename (minus ext) to IMDB for a suggested title/year. Confirms each action (occasionally IMDB::Film comes back with the wrong title or nothing at all, so full automation would be bad). `yes | rename_movies.pl` if you *really* want to do this.
#!/usr/bin/env perl
use IMDB::Film;
use File::Copy;
use autodie;
# Rename DVD Rips, with suggestion from IMDB.
my $dir = shift || '/media/usb1/vids/Movies';
opendir (my $dh, $dir);
for (sort readdir($dh)) {
next if (-d "$dir/$_");
my ($fn, $ext) = $_ =~ /(.*)\.([a-zA-Z]+)$/;
$fn || next;
my $imdb = IMDB::Film->new( crit => $fn );
my $sfn = $imdb->title . " (" . $imdb->year . ").$ext";
print "$_ -> $sfn " . ((-e "$dir/$sfn")? "(overwrite)" : "") . " [y/N]?";
chomp (my $rename = <STDIN>);
($rename =~ /^y/i) || next;
print "Renaming $_ to $sfn...";
move("$dir/$_", "$dir/$sfn");
print "done\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment