line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Amazon::DVD2IMDB; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27215
|
use LWP::Simple; |
|
1
|
|
|
|
|
114000
|
|
|
1
|
|
|
|
|
10
|
|
4
|
1
|
|
|
1
|
|
1211
|
use Net::Amazon; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Net::Amazon::Request::Keyword; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 0.03; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
|
|
|
|
|
|
my $ref = shift; |
11
|
|
|
|
|
|
|
my $class = ref( $ref ) || $ref; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $self = bless { |
14
|
|
|
|
|
|
|
token => undef, |
15
|
|
|
|
|
|
|
amazon => undef, |
16
|
|
|
|
|
|
|
@_ |
17
|
|
|
|
|
|
|
}, $class; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
die "Amazon Token Required" unless ( $self->{token} ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$self->{amazon} = new Net::Amazon( token => $self->{token} ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub convert { |
27
|
|
|
|
|
|
|
my ( $self, @titles ) = @_; |
28
|
|
|
|
|
|
|
return $self->asin2imdb( $self->dvd2asin( @titles ) ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub dvd2asin { |
32
|
|
|
|
|
|
|
my ( $self, @titles ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
@titles = map { |
35
|
|
|
|
|
|
|
my $asin = undef; |
36
|
|
|
|
|
|
|
my $r = Net::Amazon::Request::Keyword->new( keyword => $_, mode => 'dvd' ); |
37
|
|
|
|
|
|
|
my $resp = $self->{amazon}->request( $r ); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
if( $resp->is_success() ) { |
40
|
|
|
|
|
|
|
foreach my $item ( $resp->properties ) { |
41
|
|
|
|
|
|
|
$asin ||= $item->Asin(); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$asin; |
46
|
|
|
|
|
|
|
} @titles; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
wantarray ? @titles : $titles[0]; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub asin2imdb { |
52
|
|
|
|
|
|
|
my ( $self, @asin ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
@asin = map { |
55
|
|
|
|
|
|
|
my @found; |
56
|
|
|
|
|
|
|
my $page = get( "http://www.amazon.com/exec/obidos/ASIN/$_" ); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
while ( $page =~ /imdb.*?\?(\d+)/ig ) { |
59
|
|
|
|
|
|
|
push( @found, $1 ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
[ @found ]; |
63
|
|
|
|
|
|
|
} @asin; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
wantarray ? @asin : $asin[0]; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |