forked from jeffa/Media-Browser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert.pl
executable file
·42 lines (35 loc) · 1.03 KB
/
insert.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use MongoDB;
use File::Slurp;
use File::Basename;
use WWW::Mechanize;
use lib 'lib';
use MovieUtil qw( canonicalize );
my $client = MongoDB->connect( 'mongodb://localhost' );
my $db = $client->get_database( 'movies' );
my $titles = $db->get_collection( 'raw_titles' );
my $url = 'http://www.imdb.com/find?ref_=nv_sr_fn&s=tt&q=';
my $mech = WWW::Mechanize->new;
while (my $filename = <STDIN>) {
chomp( $filename );
my $term = canonicalize( $filename );
print "\n$filename - ";
if ($titles->find({ filename => $filename })->all) {
print "SKIP";
next;
} else {
print "INSERT";
$mech->get( $url . $term );
$titles->insert_one({
filename => $filename,
term => $term,
search => $mech->content,
});
sleep int rand(4);
}
}
__DATA__
find /Volumes/TV -type f \( -iname \*.divx -o -iname \*.m4v -o -iname \*.avi -o -iname \*.mkv -o -iname \*.mp4 \) -print