line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Moviepilot; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25921
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
89
|
|
7
|
1
|
|
|
1
|
|
1153
|
use JSON::Any; |
|
1
|
|
|
|
|
26582
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
11871
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
56686
|
|
|
1
|
|
|
|
|
40
|
|
9
|
1
|
|
|
1
|
|
12
|
use URI; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
10
|
1
|
|
|
1
|
|
5
|
use URI::Escape; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
86
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
786
|
use WWW::Moviepilot::Movie; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1127
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
WWW::Moviepilot - Interface to the moviepilot.de database |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 VERSION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Version 0.04 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use WWW::Moviepilot; |
29
|
|
|
|
|
|
|
my $m = WWW::Moviepilot->new({ |
30
|
|
|
|
|
|
|
api_key => ..., |
31
|
|
|
|
|
|
|
host => 'www.moviepilot.de', |
32
|
|
|
|
|
|
|
}); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# direct retrieval |
35
|
|
|
|
|
|
|
my $movie = $m->movie( 'matrix' ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# search |
38
|
|
|
|
|
|
|
my @movies = $m->search_movie( 'matrix' ); |
39
|
|
|
|
|
|
|
foreach my $movie ( @movies ) { |
40
|
|
|
|
|
|
|
print $movie->display_title; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# cast of a movie |
44
|
|
|
|
|
|
|
my @cast = $m->cast( 'matrix' ); |
45
|
|
|
|
|
|
|
foreach my $person ( @cast ) { |
46
|
|
|
|
|
|
|
print $person->last_name; |
47
|
|
|
|
|
|
|
print $person->character; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# filmography of a person |
51
|
|
|
|
|
|
|
my @filmography = $m->filmography( 'paul-newman' ); |
52
|
|
|
|
|
|
|
foreach my $movie ( @filmography ) { |
53
|
|
|
|
|
|
|
print $movie->display_title; |
54
|
|
|
|
|
|
|
print $movie->character; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
I |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 new( $args ) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Creates a new WWW::Moviepilot instance. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $m = WWW::Moviepilot->new( $args ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
C<$args> must be a hash reference, you should supply an API key: |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$args->{api_key} = ...; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
To get a valid API key you should read L. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Further optional arguments: |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over 4 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item * C (default: C) |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
The host where the requests are sent to. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item * C (default: C<< LWP::UserAgent->new >>) |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
A L compatible user agent. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=back |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub new { |
90
|
0
|
|
|
0
|
1
|
|
my ($class, $args) = @_; |
91
|
0
|
|
|
|
|
|
my $self = bless {} => $class; |
92
|
0
|
|
0
|
|
|
|
$self->{api_key} = $args->{api_key} || croak "api_key is missing at " . __PACKAGE__ . "->new()"; |
93
|
0
|
|
0
|
|
|
|
$self->{host} = $args->{host} || 'www.moviepilot.de'; |
94
|
0
|
|
0
|
|
|
|
$self->{ua} = $args->{ua} || LWP::UserAgent->new; |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
$self->{host} = 'http://' . $self->{host} unless $self->{host} =~ m{^http://}; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return $self; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 movie( $name ) | movie( $source => $id ) |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Retrieve a movie as L object. |
104
|
|
|
|
|
|
|
There are two ways to specify which movie to retrieve. |
105
|
|
|
|
|
|
|
First, you can provide the name of the movie (this name is some kind of normalised, |
106
|
|
|
|
|
|
|
I'm not sure how exactly): |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $movie = $m->movie( 'matrix' ); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The second form is to provide an alternate ID: |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $movie = $m->movie( imdb => '133093' ); |
113
|
|
|
|
|
|
|
my $movie = $m->movie( amazon => 'B00004R80K' ); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub movie { |
118
|
0
|
|
|
0
|
1
|
|
my ($self, @args) = @_; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
my $url = $self->host . '/movies/'; |
121
|
0
|
0
|
|
|
|
|
if ( @args > 2 ) { |
122
|
0
|
|
|
|
|
|
croak "invalid usage of " . __PACKAGE__ . "->movie()"; |
123
|
|
|
|
|
|
|
} |
124
|
0
|
|
|
|
|
|
$url .= join '-id-', map { uri_escape($_) } @args; |
|
0
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$url .= '.json'; |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my $uri = URI->new( $url ); |
128
|
0
|
|
|
|
|
|
$uri->query_form( api_key => $self->api_key ); |
129
|
0
|
|
|
|
|
|
my $res = $self->ua->get( $uri->as_string ); |
130
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
|
if( $res->is_error ) { |
132
|
0
|
|
|
|
|
|
croak $res->status_line; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my $json = JSON::Any->from_json( $res->decoded_content ); |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
my $movie = WWW::Moviepilot::Movie->new({ m => $self }); |
138
|
0
|
|
|
|
|
|
$movie->populate({ data => { movie => $json } }); |
139
|
0
|
|
|
|
|
|
return $movie; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 search_movie( $query ) |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Searches for a movie and returns a list with results: |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
my @movielist = $m->search_movie( 'matrix' ); |
147
|
|
|
|
|
|
|
if ( @movielist == 0 ) { |
148
|
|
|
|
|
|
|
print 'no movies found'; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
else { |
151
|
|
|
|
|
|
|
# each $movie is a WWW::Moviepilot::Movie object |
152
|
|
|
|
|
|
|
foreach my $movie ( @movielist ) { |
153
|
|
|
|
|
|
|
print $movie->display_title; # e.g. Matrix |
154
|
|
|
|
|
|
|
print $movie->production_year; # e.g. 1999 |
155
|
|
|
|
|
|
|
print scalar $movie->emotions_list; # e.g. Spannend,Aufregend |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# in list context, all *_list fields are split up by comma |
158
|
|
|
|
|
|
|
my @emotions = $movie->emotions_list; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
At most there are 20 movies returned. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
See L. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub search_movie { |
169
|
0
|
|
|
0
|
1
|
|
my ($self, $query) = @_; |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
my $uri = URI->new( $self->host . '/searches/movies.json' ); |
172
|
0
|
|
|
|
|
|
$uri->query_form( |
173
|
|
|
|
|
|
|
api_key => $self->api_key, |
174
|
|
|
|
|
|
|
q => $query, |
175
|
|
|
|
|
|
|
); |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
my $res = $self->ua->get( $uri->as_string ); |
178
|
0
|
0
|
|
|
|
|
if ( $res->is_error ) { |
179
|
0
|
|
|
|
|
|
croak $res->status_line; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
my $o = JSON::Any->from_json( $res->decoded_content ); |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
|
my @result = (); |
185
|
0
|
|
|
|
|
|
foreach my $entry ( @{ $o->{movies} } ) { |
|
0
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
my $movie = WWW::Moviepilot::Movie->new({ m => $self }); |
187
|
0
|
|
|
|
|
|
$movie->populate({ data => { movie => $entry } }); |
188
|
0
|
|
|
|
|
|
push @result, $movie; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
return @result; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 person( $name ) |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Retrieve a person as L object. |
197
|
|
|
|
|
|
|
You should provide the name of the movie (this name is some kind of normalised, |
198
|
|
|
|
|
|
|
I'm not sure how exactly): |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
my $person = $m->person( 'paul-newman' ); |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub person { |
205
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
my $uri = URI->new( $self->host . '/people/' . uri_escape($name) . '.json' ); |
208
|
0
|
|
|
|
|
|
$uri->query_form( api_key => $self->api_key ); |
209
|
0
|
|
|
|
|
|
my $res = $self->ua->get( $uri->as_string ); |
210
|
|
|
|
|
|
|
|
211
|
0
|
0
|
|
|
|
|
if( $res->is_error ) { |
212
|
0
|
|
|
|
|
|
croak $res->status_line; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
my $json = JSON::Any->from_json( $res->decoded_content ); |
216
|
0
|
|
|
|
|
|
my $person = WWW::Moviepilot::Person->new({ m => $self }); |
217
|
0
|
|
|
|
|
|
$person->populate({ data => { person => $json } }); |
218
|
0
|
|
|
|
|
|
return $person; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 search_person( $query ) |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Searches for a person and returns a list with results: |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
my @people = $m->search_person( 'Paul Newman' ); |
226
|
|
|
|
|
|
|
if ( @people == 0 ) { |
227
|
|
|
|
|
|
|
print 'no people found'; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
else { |
230
|
|
|
|
|
|
|
# each $person is a WWW::Moviepilot::Person object |
231
|
|
|
|
|
|
|
foreach my $person ( @person ) { |
232
|
|
|
|
|
|
|
print $person->first_name; # e.g. Paul |
233
|
|
|
|
|
|
|
print $person->last_name; # e.g. Newman |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
See L. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=cut |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub search_person { |
242
|
0
|
|
|
0
|
1
|
|
my ($self, $query) = @_; |
243
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
my $uri = URI->new( $self->host . '/searches/people.json' ); |
245
|
0
|
|
|
|
|
|
$uri->query_form( |
246
|
|
|
|
|
|
|
api_key => $self->api_key, |
247
|
|
|
|
|
|
|
q => $query, |
248
|
|
|
|
|
|
|
); |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
my $res = $self->ua->get( $uri->as_string ); |
251
|
0
|
0
|
|
|
|
|
if ( $res->is_error ) { |
252
|
0
|
|
|
|
|
|
croak $res->status_line; |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
0
|
|
|
|
|
|
my $o = JSON::Any->from_json( $res->decoded_content ); |
256
|
|
|
|
|
|
|
|
257
|
0
|
|
|
|
|
|
my @result = (); |
258
|
0
|
|
|
|
|
|
foreach my $entry ( @{ $o->{people} } ) { |
|
0
|
|
|
|
|
|
|
259
|
0
|
|
|
|
|
|
my $person = WWW::Moviepilot::Person->new({ m => $self }); |
260
|
0
|
|
|
|
|
|
$person->populate({ data => { person => $entry } }); |
261
|
0
|
|
|
|
|
|
push @result, $person; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
0
|
|
|
|
|
|
return @result; |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head2 cast( $name ) |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Returns the cast of a movie. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
my $m = WWW::Moviepilot->new(...); |
272
|
|
|
|
|
|
|
my @cast = $m->cast('brust-oder-keule'); |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
See L. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=cut |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub cast { |
279
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
280
|
0
|
|
|
|
|
|
my $movie = WWW::Moviepilot::Movie->new({ m => $self }); |
281
|
0
|
|
|
|
|
|
return $movie->cast( $name ); |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head2 filmography( $name ) |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
Returns the filmography of a person. |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
my $m = WWW::Moviepilot->new(...); |
289
|
|
|
|
|
|
|
my @filmography = $m->filmography('paul-newman'); |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
See L. |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=cut |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
sub filmography { |
296
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
297
|
0
|
|
|
|
|
|
my $person = WWW::Moviepilot::Person->new({ m => $self }); |
298
|
0
|
|
|
|
|
|
return $person->filmography( $name ); |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=head2 api_key |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
my $api_key = $m->api_key; |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
Returns the API key provided to the C constructor. |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=cut |
308
|
|
|
|
|
|
|
|
309
|
0
|
|
|
0
|
1
|
|
sub api_key { return shift->{api_key} } |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=head2 ua |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
my $ua = $m->ua; |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
Returns the user agent, usually a L. |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=cut |
318
|
|
|
|
|
|
|
|
319
|
0
|
|
|
0
|
1
|
|
sub ua { return shift->{ua} } |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=head2 host |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
my $host = $m->host; |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
Returns host which the requests are sent to provided to the C constructor. |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
=cut |
328
|
|
|
|
|
|
|
|
329
|
0
|
|
|
0
|
1
|
|
sub host { return shift->{host} } |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
1; |
332
|
|
|
|
|
|
|
__END__ |