Skip to content

Instantly share code, notes, and snippets.

@jonhoo
Created September 18, 2012 11:03
Show Gist options
  • Save jonhoo/3742595 to your computer and use it in GitHub Desktop.
Save jonhoo/3742595 to your computer and use it in GitHub Desktop.
File for looking up movie files in IMDb
#!/usr/bin/perl
use strict;
use warnings;
use IMDB::Film;
my $promptDelete = 0;
if (@ARGV > 0 and $ARGV[0] eq "-d") {
$promptDelete = 1;
shift @ARGV;
}
die "Usage: $0 lookup, [lookup, ...]\n" if @ARGV == 0;
foreach my $a (@ARGV) {
my $lookup = $a;
$lookup =~ s/\.\w{3}$//;
my $before = $lookup;
$lookup =~ s/\b\w*rip\b//gi;
$lookup =~ s/\b\w*sub\b//gi;
$lookup =~ s/\b\w*cam\b//gi;
$lookup =~ s/\b\w*scr\b//gi;
$lookup =~ s/\.\d{4}\././gi;
$lookup =~ s/\b\d+[pi]\b//gi;
$lookup =~ s/\b[\d\.]+[MKGT]B\b//gi;
$lookup =~ s/\b(limited|ts|)\b//gi;
$lookup =~ s/(read.?nfo|repack|proper|unrated)//gi;
$lookup =~ s/(xvid|ac3|divx|mkv|x264|bluray|dts|dolby|thx|5\.1)//gi;
my $after = $lookup;
$lookup =~ s/\[[^\]]*\]//gi;
$lookup =~ s/\([^\)]*\)//gi;
$lookup =~ s/\./ /g;
if ($before ne $after) {
# If we have removed something, file probably still contains release group
# Remove last word (usually release group)
$lookup =~ s/[\s\-]*$//;
$lookup =~ s/^(.*)\b.+$/$1/;
$lookup =~ s/[\s\-]*$//;
}
my $hit = new IMDB::Film(crit => $lookup);
if (!$hit->status) {
print "Found no matching IMDB records for '$lookup': " . $hit->error . "\n";
next;
}
print "[ Search: $before ]\n";
print "Title:\t" . $hit->title() . " (from " . $hit->year() . ")\n";
print "Plot:\t" . $hit->plot() . "\n";
if (-e $a && $promptDelete) {
print "Delete this file? [y/N] ";
if (<STDIN> =~ /^y/i) {
unlink $a;
}
}
print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment