Debian Codegraph @

lib/IMDB/Film.pm

raw symbols SCIP
1 =head1 NAME
2
3 IMDB::Film - OO Perl interface to the movies database IMDB.
4
5 =head1 SYNOPSIS
6
7 use IMDB::Film;
8
9 #
10 # Retrieve a movie information by its IMDB code
11 #
12 my $imdbObj = new IMDB::Film(crit => 227445);
13
14 or
15
16 #
17 # Retrieve a movie information by its title
18 #
19 my $imdbObj = new IMDB::Film(crit => 'Troy');
20
21 or
22
23 #
24 # Parse already stored HTML page from IMDB
25 #
26 my $imdbObj = new IMDB::Film(crit => 'troy.html');
27
28 if($imdbObj->status) {
29 print "Title: ".$imdbObj->title()."\n";
30 print "Year: ".$imdbObj->year()."\n";
31 print "Plot Symmary: ".$imdbObj->plot()."\n";
32 } else {
33 print "Something wrong: ".$imdbObj->error;
34 }
35
36 =head1 DESCRIPTION
37
38 =head2 Overview
39
40 IMDB::Film is an object-oriented interface to the IMDB.
41 You can use that module to retrieve information about film:
42 title, year, plot etc.
43
44 =cut
45
46 package IMDB::Filmscip-perl cpan IMDB-Film 0.53 IMDB/Film/;
47
48 use strictscip-perl cpan IMDB-Film 0.53 strict/;
49 use warningsscip-perl cpan IMDB-Film 0.53 warnings/;
50
51 use basescip-perl cpan IMDB-Film 0.53 base/ qw(IMDB::BaseClass);
52
53 use Carpscip-perl cpan IMDB-Film 0.53 Carp/;
54 use Data::Dumperscip-perl cpan IMDB-Film 0.53 Data/Dumper/;
55
56 use fieldsscip-perl cpan IMDB-Film 0.53 fields/ qw( _title
57 _kind
58 _year
59 _episodes
60 _episodeof
61 _summary
62 _cast
63 _directors
64 _writers
65 _cover
66 _language
67 _country
68 _top_info
69 _rating
70 _genres
71 _tagline
72 _plot
73 _also_known_as
74 _certifications
75 _duration
76 _full_plot
77 _trivia
78 _goofs
79 _awards
80 _official_sites
81 _release_dates
82 _aspect_ratio
83 _mpaa_info
84 _company
85 _connections
86 _full_companies
87 _recommendation_movies
88 _plot_keywords
89 _big_cover_url
90 _big_cover_page
91 _storyline
92 full_plot_url
93 );
94
95 use varsscip-perl cpan IMDB-Film 0.53 vars/ qw( $VERSION %FIELDS %FILM_CERT %FILM_KIND $PLOT_URL );
96
97 use constantscip-perl cpan IMDB-Film 0.53 constant/ CLASS_NAMEscip-perl cpan IMDB-Film 0.53 IMDB/Film/CLASS_NAME(). => 'IMDB::Film';
98 use constantscip-perl cpan IMDB-Film 0.53 constant/ FORCEDscip-perl cpan IMDB-Film 0.53 IMDB/Film/FORCED(). => 1;
99 use constantscip-perl cpan IMDB-Film 0.53 constant/ USE_CACHEscip-perl cpan IMDB-Film 0.53 IMDB/Film/USE_CACHE(). => 1;
100 use constantscip-perl cpan IMDB-Film 0.53 constant/ DEBUG_MODscip-perl cpan IMDB-Film 0.53 IMDB/Film/DEBUG_MOD(). => 1;
101 use constantscip-perl cpan IMDB-Film 0.53 constant/ EMPTY_OBJECTscip-perl cpan IMDB-Film 0.53 IMDB/Film/EMPTY_OBJECT(). => 0;
102 use constantscip-perl cpan IMDB-Film 0.53 constant/ MAIN_TAGscip-perl cpan IMDB-Film 0.53 IMDB/Film/MAIN_TAG(). => 'h4';
103
104 BEGIN {
105 $VERSIONscip-perl cpan IMDB-Film 0.53 IMDB/Film/$VERSION. = '0.53';
106
107 # Convert age gradation to the digits
108 # TODO: Store this info into constant file
109 %FILM_CERTscip-perl cpan IMDB-Film 0.53 IMDB/Film/`%FILM_CERT`. = ( G => 'All',
110 R => 16,
111 'NC-17' => 16,
112 PG => 13,
113 'PG-13' => 13
114 );
115
116 %FILM_KINDscip-perl cpan IMDB-Film 0.53 IMDB/Film/`%FILM_KIND`. = ( '' => 'movie',
117 TV => 'tv movie',
118 V => 'video movie',
119 mini => 'tv mini series',
120 VG => 'video game',
121 S => 'tv series',
122 E => 'episode'
123 );
124 }
125
126 {
127 my %_defaults = (
128 cache => 0,
129 debug => 0,
130 error => [],
131 cache_exp => '1 h',
132 cache_root => '/tmp',
133 matched => [],
134 host => 'www.imdb.com',
135 query => 'title/tt',
136 search => 'find?s=tt&exact=true&q=',
137 status => 0,
138 timeout => 10,
139 user_agent => 'Mozilla/5.0',
140 decode_html => 1,
141 full_plot_url => 'http://www.imdb.com/rg/title-tease/plotsummary/title/tt',
142 _also_known_as => [],
143 _official_sites => [],
144 _release_dates => [],
145 _duration => [],
146 _top_info => [],
147 _cast => [],
148 );
149
150 sub _get_default_attrsscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_default_attrs(). { keysscip-perl cpan IMDB-Film 0.53 IMDB/Film/keys(). %_defaults }
151 sub _get_default_valuescip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_default_value(). {
152 my($self, $attr) = @_scip-perl cpan IMDB-Film 0.53 IMDB/Film/`@_`.;
153 $_defaults{$attr};
154 }
155 }
156
157 =head2 Constructor
158
159 =over 4
160
161 =item new()
162
163 Object's constructor. You should pass as parameter movie title or IMDB code.
164
165 my $imdb = new IMDB::Film(crit => <some code>);
166
167 or
168
169 my $imdb = new IMDB::Film(crit => <some title>);
170
171 or
172 my $imdb = new IMDB::Film(crit => <HTML file>);
173
174 For more infomation about base methods refer to IMDB::BaseClass.
175
176 =item _init()
177
178 Initialize object.
179
180 =cut
181
182 sub _initscip-perl cpan IMDB-Film 0.53 IMDB/Film/_init(). {
183 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
184 my %args = @_scip-perl cpan IMDB-Film 0.53 IMDB/Film/`@_`.;
185
186 croakscip-perl cpan IMDB-Film 0.53 IMDB/Film/croak(). "Film IMDB ID or Title should be defined!" if !$args{crit} && !$args{file};
187
188 $self->SUPER::_initscip-perl cpan IMDB-Film 0.53 IMDB/Film/`SUPER::_init`().(%args);
189
190 $self->titlescip-perl cpan IMDB-Film 0.53 IMDB/Film/title().(FORCED, \%args);
191
192 unless($self->titlescip-perl cpan IMDB-Film 0.53 IMDB/Film/title().) {
193 $self->statusscip-perl cpan IMDB-Film 0.53 IMDB/Film/status().(EMPTY_OBJECT);
194 $self->errorscip-perl cpan IMDB-Film 0.53 IMDB/Film/error().('Not Found');
195 return;
196 }
197
198 for my $prop (grepscip-perl cpan IMDB-Film 0.53 IMDB/Film/grep(). { /^_/ &&
199 !/^(_title|_code|_full_plot|_official_sites|_release_dates|_connections|_full_companies|_plot_keywords|_big_cover_url|_big_cover_page)$/ } sortscip-perl cpan IMDB-Film 0.53 IMDB/Film/sort(). keysscip-perl cpan IMDB-Film 0.53 IMDB/Film/keys(). %FIELDSscip-perl cpan IMDB-Film 0.53 IMDB/Film/`%FIELDS`.) {
200 ($prop) = $prop =~ /^_(.*)/;
201 $self->$propscip-perl cpan IMDB-Film 0.53 IMDB/Film/$prop().(FORCED);
202 }
203 }
204
205 =back
206
207 =head2 Options
208
209 =over 4
210
211 =item year
212
213 Define a movie's year. It's useful to use it to get the proper movie by its title:
214
215 my $imdbObj = new IMDB::Film(crit => 'Jack', year => 2003);
216 print "Got #" . $imdbObj->code . " " . $imdbObj->title . "\n"; #0379836
217
218 =item proxy
219
220 defines proxy server name and port:
221
222 proxy => 'http://proxy.myhost.com:80'
223
224 By default object tries to get proxy from environment
225
226 =item debug
227
228 switches on debug mode to display useful debug messages. Can be 0 or 1 (0 by default)
229
230 =item cache
231
232 indicates use cache or not to store retrieved page content. Can be 0 or 1 (0 by default)
233
234 =item cache_root
235
236 specifies a directory to store cache data. By default it use /tmp/FileCache for *NIX OS
237
238 =item cache_exp
239
240 specifies an expiration time for cache. By default, it's 1 hour
241
242 =item clear_cache
243
244 indicates clear cached data before get request to IMDB.com or not
245
246 =item timeout
247
248 specifies a timeout for HTTP connection in seconds (10 sec by default)
249
250 =item user_agent
251
252 specifies an user agent for request ('Mozilla/5.0' by default)
253
254 =item full_plot_url
255
256 specifies a full plot url for specified movie
257
258 =item host
259
260 specifies a host name for IMDB site. By default it's www.imdb.com
261
262 =item query
263
264 specifies a query string to get specified movie by its ID. By defualt it's 'title/tt'
265
266 =item search
267
268 specifies query string to make a search movie by its title. By default it's 'find?tt=on;mx=20;q='
269
270
271 Example:
272
273 my $imdb = new IMDB::Film( crit => 'Troy',
274 user_agent => 'Opera/8.x',
275 timeout => 2,
276 debug => 1,
277 cache => 1,
278 cache_root => '/tmp/imdb_cache',
279 cache_exp => '1 d',
280 );
281
282 It'll create an object with critery 'Troy', user agent 'Opera', timeout 2 seconds, debug mode on,
283 using cache with directory '/tmp/imdb_cache' and expiration time in 1 day.
284
285 =cut
286
287 sub full_plot_urlscip-perl cpan IMDB-Film 0.53 IMDB/Film/full_plot_url(). {
288 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
289 if(@_scip-perl cpan IMDB-Film 0.53 IMDB/Film/`@_`.) { $self->{full_plot_url} = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). }
290 return $self->{full_plot_url}
291 }
292
293 sub fieldsscip-perl cpan IMDB-Film 0.53 IMDB/Film/fields(). {
294 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
295 return \%FIELDSscip-perl cpan IMDB-Film 0.53 IMDB/Film/`%FIELDS`.;
296 }
297
298 =back
299
300 =head2 Object Private Methods
301
302 =over 4
303
304 =item _search_film()
305
306 Implemets functionality to search film by name.
307
308 =cut
309
310 sub _search_filmscip-perl cpan IMDB-Film 0.53 IMDB/Film/_search_film(). {
311 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
312 my $args = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || {};
313
314 return $self->SUPER::_search_resultsscip-perl cpan IMDB-Film 0.53 IMDB/Film/`SUPER::_search_results`().('^\/title\/tt(\d+)', '/td', $args->{year});
315 }
316
317 =back
318
319 =head2 Object Public Methods
320
321 =over 4
322
323 =item status()
324
325 Indicates a status of IMDB object:
326
327 0 - empty object;
328 1 - loaded from file;
329 2 - loaded from internet request;
330 3 - loaded from cache.
331
332 =item status_descr()
333
334 Return a description for IMDB object status. Can be 'Empty', 'Filed', 'Fresh' and 'Cached':
335
336
337 if($film->status) {
338 print "This is a " . $film->status_descr . " object!";
339 } else {
340 die "Cannot retrieve IMDB object!";
341 }
342
343 =item title()
344
345 Retrieve film title from film page. If was got search page instead
346 of film page this method calls method _search_film to get list
347 matched films and continue to process first one:
348
349 my $title = $film->title();
350
351 =cut
352
353 sub titlescip-perl cpan IMDB-Film 0.53 IMDB/Film/title(). {
354 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
355 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
356 my $args = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || {};
357
358 if($forced) {
359 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
360
361 $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('title');
362 my $title = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
363 if($title =~ /Find \- IMDb/i) {
364 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("Go to search page ...", 'DEBUG');
365 $title = $self->_search_filmscip-perl cpan IMDB-Film 0.53 IMDB/Film/_search_film().($args);
366 }
367
368 if($title) {
369 $self->retrieve_codescip-perl cpan IMDB-Film 0.53 IMDB/Film/retrieve_code().($parser, 'http://www.imdb.com/title/tt(\d+)') unless $self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code().;
370 $title =~ s/\*/\\*/g;
371 $title = $self->_decode_special_symbolsscip-perl cpan IMDB-Film 0.53 IMDB/Film/_decode_special_symbols().($title);
372
373 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("title: $title", 'DEBUG');
374
375 # TODO: implement parsing of TV series like ALF (TV Series 1986–1990)
376 $title =~ s/^imdb\s+\-\s+//i;
377 ($self->{_title}, $self->{_year}, $self->{_kind}) = $title =~ m!(.*?)\s+\((\d{4})(?:/[IVX]+)\)(?:\s\((\w*)\))?!;
378 unless($self->{_title}) {
379 ($self->{_title}, $self->{_kind}, $self->{_year}) = $title =~ m!(.*?)\s+\((.*?)?\s?([0-9\-]*\s?)\)!;
380 }
381 $self->{_kind} = 'Movie' unless $self->{_kind}; # Default kind should be movie
382
383 # "The Series" An Episode (2005)
384 # "The Series" (2005)
385 if( $self->{_title} =~ /\"[^\"]+\"(\s+.+\s+)?/ ) {
386 $self->{_kind} = $1scip-perl cpan IMDB-Film 0.53 IMDB/Film/$1. ? 'E' : 'S';
387 }
388 }
389 }
390
391 return $self->{_title};
392 }
393
394 =item kind()
395
396 Get kind of movie:
397
398 my $kind = $film->kind();
399
400 Possible values are: 'movie', 'tv series', 'tv mini series', 'video game', 'video movie', 'tv movie', 'episode'.
401
402 =cut
403
404 sub kindscip-perl cpan IMDB-Film 0.53 IMDB/Film/kind(). {
405 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
406 return existsscip-perl cpan IMDB-Film 0.53 IMDB/Film/exists(). $FILM_KINDscip-perl cpan IMDB-Film 0.53 IMDB/Film/`%FILM_KIND`.{$self->{_kind}} ? $FILM_KINDscip-perl cpan IMDB-Film 0.53 IMDB/Film/`%FILM_KIND`.{$self->{_kind}} : lcscip-perl cpan IMDB-Film 0.53 IMDB/Film/lc().($self->{_kind});
407 }
408
409 =item year()
410
411 Get film year:
412
413 my $year = $film->year();
414
415 =cut
416
417 sub yearscip-perl cpan IMDB-Film 0.53 IMDB/Film/year(). {
418 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
419 return $self->{_year};
420 }
421
422 =item connections()
423
424 Retrieve connections for the movie as an arrays of hashes with folloeing structure
425
426 {
427 follows => [ { id => <id>, title => <name>, year => <year>, ..., } ],
428 followed_by => [ { id => <id>, title => <name>, year => <year>, ..., } ],
429 references => [ { id => <id>, title => <name>, year => <year>, ..., } ],
430 referenced_in => [ { id => <id>, title => <name>, year => <year>, ..., } ],
431 featured_in => [ { id => <id>, title => <name>, year => <year>, ..., } ],
432 spoofed_by => [ { id => <id>, title => <name>, year => <year>, ..., } ],
433 }
434
435 my %connections = %{ $film->connections() };
436
437 =cut
438
439 sub connectionsscip-perl cpan IMDB-Film 0.53 IMDB/Film/connections(). {
440 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
441
442 unless($self->{_connections}) {
443 my $page;
444 $page = $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->getscip-perl cpan IMDB-Film 0.53 IMDB/Film/get().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . '_connections') if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
445
446 unless($page) {
447 my $url = "http://". $self->{host} . "/" . $self->{query} . $self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . "/trivia?tab=mc";
448 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("URL for movie connections is $url ...", 'DEBUG');
449
450 $page = $self->_get_page_from_internetscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_page_from_internet().($url);
451 $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->setscip-perl cpan IMDB-Film 0.53 IMDB/Film/set().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code()..'_connections', $page, $self->_cache_expscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache_exp().) if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
452 }
453
454 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED, \$page);
455
456 my $group = undef;
457 my %result;
458 my @lookFor = ('h4');
459 while (my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(@lookFor)) {
460 if ($tag->[0] eq 'h4') {
461 $group = HTML::Entities::encode_entitiesscip-perl cpan IMDB-Film 0.53 HTML/Entities/encode_entities().($parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().);
462 $group = lcscip-perl cpan IMDB-Film 0.53 IMDB/Film/lc().($group);
463 $group =~ s/\s+/_/g;
464 $group =~ s/(&nbsp;|\?|\:)//;
465 $group =~ s/&amp;/and/;
466 $result{$group} = [];
467 @lookFor = ('h4', 'a', 'hr', 'hr/');
468 } elsif ($tag->[0] eq 'a') {
469 my $id;
470 ($id)= $tag->[1]->{href} =~ /(\d+)/ if $tag->[1]->{href};
471 my $name = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().;
472
473 # Handle series episodes (usually in 'referenced' sections)
474 my($series,$t,$s,$e) = ($name =~ /^(.*?): *(.*?) *\(?#(\d+)\.(\d+)\)?$/);
475 $name = $series if definedscip-perl cpan IMDB-Film 0.53 IMDB/Film/defined(). $series;
476
477 $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('/a');
478 my $next = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().();
479 my %film = ('id' => $id, 'title' => $name);
480 if(definedscip-perl cpan IMDB-Film 0.53 IMDB/Film/defined(). $t) {
481 $film{'series_title'} = $t;
482 $film{'season'} = $s;
483 $film{'episode'} = $e;
484 }
485
486 $film{'year'} = $1scip-perl cpan IMDB-Film 0.53 IMDB/Film/$1. if $next =~ /\((\d{4})\)/;
487 next if ($next =~ /\(VG\)/);
488 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @{$result{$group}}, \%film;
489 } else {
490 # Stop when we hit the divider
491 last;
492 }
493 }
494
495 $self->{_connections} = \%result;
496 }
497
498 return $self->{_connections};
499 }
500
501
502 =item full_companies()
503
504 Retrieve companies for the movie as an array where each item has following stucture:
505
506 {
507 production => [ { name => <company name>, url => <imdb url>, extra => <specific task> } ],
508 distributors => [ { name => <company name>, url => <imdb url>, extra => <specific task> } ],
509 special_effects => [ { name => <company name>, url => <imdb url>, extra => <specific task> } ],
510 other => [ { name => <company name>, url => <imdb url>, extra => <specific task> } ],
511 }
512
513 my %full_companies = %{ $film->full_companies() };
514
515 =cut
516
517 sub full_companiesscip-perl cpan IMDB-Film 0.53 IMDB/Film/full_companies(). {
518 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
519
520 unless($self->{_full_companies}) {
521 my $page;
522 $page = $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->getscip-perl cpan IMDB-Film 0.53 IMDB/Film/get().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . '_full_companies') if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
523
524 unless($page) {
525 my $url = "http://". $self->{host} . "/" . $self->{query} . $self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . "/companycredits";
526 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("URL for company credits is $url ...", 'DEBUG');
527
528 $page = $self->_get_page_from_internetscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_page_from_internet().($url);
529 $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->setscip-perl cpan IMDB-Film 0.53 IMDB/Film/set().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code()..'_full_companies', $page, $self->_cache_expscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache_exp().) if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
530 }
531
532 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED, \$page);
533 my $group = undef;
534 my %result;
535 my @lookFor = ('h2');
536 while (my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(@lookFor)) {
537 if ($tag->[0] eq 'h2') {
538 $group = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().;
539 $group =~ s/ compan(y|ies)//i;
540 $group =~ tr/A-Z/a-z/;
541 $group =~ s/\s+/_/g;
542 $result{$group} = [];
543 @lookFor = ('h2', 'a', 'hr', 'hr/');
544 } elsif($tag->[0] eq 'a') {
545
546 my($url) = $tag->[1]->{href};
547 my $name = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().;
548
549 $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('/a');
550 my $next = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().();
551 $next =~ s/^[\t \xA0]+//; # nbsp comes out as \xA0
552 my %company = ( 'url' => $url,
553 'name' => $name,
554 'extra' => $next );
555 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @{$result{$group}}, \%company;
556 } else {
557 # Stop when we hit the divider
558 last;
559 }
560 }
561
562 $self->{_full_companies} = \%result;
563 }
564
565 return $self->{_full_companies};
566 }
567
568 =item company()
569
570 Returns a list of companies given for a specified movie:
571
572 my $company = $film->company();
573
574 or
575
576 my @companies = $film->company();
577
578 =cut
579
580 sub companyscip-perl cpan IMDB-Film 0.53 IMDB/Film/company(). {
581 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
582
583 unless($self->{_company}) {
584 my @companies = splitscip-perl cpan IMDB-Film 0.53 IMDB/Film/split(). /\s?\,\s?/, $self->_get_simple_propscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_simple_prop().('Production Co');
585 $self->{_company} = \@companies;
586 }
587
588 return wantarrayscip-perl cpan IMDB-Film 0.53 IMDB/Film/wantarray(). ? $self->{_company} : $self->{_company}[0];
589 }
590
591 =item episodes()
592
593 Retrieve episodes info list each element of which is hash reference for tv series -
594 { id => <ID>, title => <Title>, season => <Season>, episode => <Episode>, date => <Date>, plot => <Plot> }:
595
596 my @episodes = @{ $film->episodes() };
597
598 =cut
599
600 sub episodesscip-perl cpan IMDB-Film 0.53 IMDB/Film/episodes(). {
601 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
602
603 return [] if !$self->kindscip-perl cpan IMDB-Film 0.53 IMDB/Film/kind(). or $self->kindscip-perl cpan IMDB-Film 0.53 IMDB/Film/kind(). !~ /tv serie/i;
604
605 unless($self->{_episodes}) {
606 my $page;
607 $page = $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->getscip-perl cpan IMDB-Film 0.53 IMDB/Film/get().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . '_episodes') if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
608
609 unless($page) {
610 my $url = "http://". $self->{host} . "/" . $self->{query} . $self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . "/epcast";
611 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("URL for episodes is $url ...", 'DEBUG');
612
613 $page = $self->_get_page_from_internetscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_page_from_internet().($url);
614 $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->setscip-perl cpan IMDB-Film 0.53 IMDB/Film/set().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code()..'_episodes', $page, $self->_cache_expscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache_exp().) if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
615 }
616
617 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED, \$page);
618 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('h4')) {
619 my $id;
620 my($season, $episode);
621 next unless(($season, $episode) = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text(). =~ /Season\s+(.*?),\s+Episode\s+([^:]+)/);
622 my $imdb_tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('a');
623 ($id) = $imdb_tag->[1]->{href} =~ /(\d+)/ if $imdb_tag->[1]->{href};
624 my $title = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().;
625 $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('b');
626 my($date) = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().;
627 $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('br');
628 my $plot = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().;
629
630 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @{ $self->{_episodes} }, {
631 season => $season,
632 episode => $episode,
633 id => $id,
634 title => $title,
635 date => $date,
636 plot => $plot
637 };
638 }
639 }
640
641 return $self->{_episodes};
642 }
643
644 =item episodeof()
645
646 Retrieve parent tv series list each element of which is hash reference for episode -
647 { id => <ID>, title => <Title>, year => <Year> }:
648
649 my @tvseries = @{ $film->episodeof() };
650
651 =cut
652
653 sub episodeofscip-perl cpan IMDB-Film 0.53 IMDB/Film/episodeof(). {
654 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
655 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
656
657 return if !$self->kindscip-perl cpan IMDB-Film 0.53 IMDB/Film/kind(). or $self->kindscip-perl cpan IMDB-Film 0.53 IMDB/Film/kind(). ne "episode";
658
659 if($forced) {
660 my($episodeof, $title, $year, $episode, $season, $id);
661 my($parser) = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
662
663 while($parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(MAIN_TAG)) {
664 last if $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text(). =~ /^TV Series/i;
665 }
666
667 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('a')) {
668 ($title, $year) = ($1scip-perl cpan IMDB-Film 0.53 IMDB/Film/$1., $2scip-perl cpan IMDB-Film 0.53 IMDB/Film/$2.) if $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text(). =~ m!(.*?)\s+\(([\d\?]{4}).*?\)!;
669 last unless $tag->[1]{href} =~ /title/i;
670 ($id) = $tag->[1]{href} =~ /(\d+)/;
671 }
672
673 #start again
674 $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
675 while($parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(MAIN_TAG)) {
676 last if $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text(). =~ /^Original Air Date/i;
677 }
678
679 $parser->get_tokenscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_token().;
680 ($season, $episode) = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text(). =~ /\(Season\s+(\d+),\s+Episode\s+(\d+)/;
681
682 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @{ $self->{_episodeof} }, {title => $title, year => $year, id => $id, season => $season, episode => $episode};
683 }
684
685 return $self->{_episodeof};
686 }
687
688 =item cover()
689
690 Retrieve url of film cover:
691
692 my $cover = $film->cover();
693
694 =cut
695
696 sub coverscip-perl cpan IMDB-Film 0.53 IMDB/Film/cover(). {
697 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
698 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
699
700 if($forced) {
701 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
702 my $cover;
703
704 my $title = quotemetascip-perl cpan IMDB-Film 0.53 IMDB/Film/quotemeta().($self->titlescip-perl cpan IMDB-Film 0.53 IMDB/Film/title().);
705 while(my $img_tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('img')) {
706 $img_tag->[1]{alt} ||= '';
707
708 last if $img_tag->[1]{alt} =~ /^poster not submitted/i;
709
710 if($img_tag->[1]{alt} =~ /Poster$/) {
711 $cover = $img_tag->[1]{src};
712 last;
713 }
714 }
715 $self->{_cover} = $cover;
716 }
717
718 return $self->{_cover};
719 }
720
721 sub top_infoscip-perl cpan IMDB-Film 0.53 IMDB/Film/top_info(). {
722 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
723 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
724 if($forced or !$self->{'_top_info'}) {
725 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
726 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('div')) {
727 last if $tag->[1]->{class} && $tag->[1]->{class} eq 'article highlighted';
728 }
729 my $text = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().('span');
730 my @top_items = splitscip-perl cpan IMDB-Film 0.53 IMDB/Film/split(). /\s?\|\s?/, $text;
731 $self->{_top_info} = \@top_items;
732 }
733 return $self->{_top_info};
734 }
735
736 =item recommendation_movies()
737
738 Return a list of recommended movies for specified one as a hash where each key is a movie ID in IMDB and
739 value - movie's title:
740
741 $recommendation_movies = $film->recommendation_movies();
742
743 For example, the list of recommended movies for Troy will be similar to that:
744
745 __DATA__
746 $VAR1 = {
747 '0416449' => '300',
748 '0167260' => 'The Lord of the Rings: The Return of the King',
749 '0442933' => 'Beowulf',
750 '0320661' => 'Kingdom of Heaven',
751 '0172495' => 'Gladiator'
752 };
753
754 =cut
755
756 sub recommendation_moviesscip-perl cpan IMDB-Film 0.53 IMDB/Film/recommendation_movies(). {
757 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
758 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
759
760 if($forced) {
761 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
762
763 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('h2')) {
764 my $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
765 last if $text =~ /recommendations/i;
766 }
767
768 my %result = ();
769 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().()) {
770 last if $tag->[0] eq '/table';
771
772 my $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
773 if($tag->[0] eq 'a' && $text && $tag->[1]{href} =~ /tt(\d+)/) {
774 $result{$1scip-perl cpan IMDB-Film 0.53 IMDB/Film/$1.} = $text;
775 }
776 }
777
778 $self->{_recommendation_movies} = \%result;
779 }
780
781 return $self->{_recommendation_movies};
782 }
783
784 =item directors()
785
786 Retrieve film directors list each element of which is hash reference -
787 { id => <ID>, name => <Name> }:
788
789 my @directors = @{ $film->directors() };
790
791 =cut
792
793 sub directorsscip-perl cpan IMDB-Film 0.53 IMDB/Film/directors(). {
794 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
795 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
796
797 if($forced) {
798 my ($parser) = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
799 my (@directors, $tag);
800
801 while($tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(MAIN_TAG)) {
802 my $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().;
803 last if $text =~ /direct(?:ed|or)/i;
804 }
805
806 while ($tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().() ) {
807 my $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
808
809 last if $text =~ /^writ(?:ing|ers)/i or $tag->[0] eq '/div';
810
811 if($tag->[0] eq 'a' && $tag->[1]{href} && $text !~ /(img|more)/i) {
812 my($id) = $tag->[1]{href} =~ /(\d+)/;
813 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @directors, {id => $id, name => $text};
814 }
815 }
816
817 $self->{_directors} = \@directors;
818 }
819
820 return $self->{_directors};
821 }
822
823 =item writers()
824
825 Retrieve film writers list each element of which is hash reference -
826 { id => <ID>, name => <Name> }:
827
828 my @writers = @{ $film->writers() };
829
830 <I>Note: this method returns Writing credits from movie main page. It maybe not
831 contain a full list!</I>
832
833 =cut
834
835 sub writersscip-perl cpan IMDB-Film 0.53 IMDB/Film/writers(). {
836 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
837 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
838
839 if($forced) {
840 my ($parser) = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
841 my (@writers, $tag);
842
843 while($tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(MAIN_TAG)) {
844 last if $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text(). =~ /writ(?:ing|ers|er)/i;
845 }
846
847 while($tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().()) {
848 my $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
849 last if $tag->[0] eq '/div';
850
851 if($tag->[0] eq 'a' && $tag->[1]{href} && $text !~ /more/i && $text !~ /img/i) {
852 if(my($id) = $tag->[1]{href} =~ /nm(\d+)/) {
853 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @writers, {id => $id, name => $text};
854 }
855 }
856 }
857
858 $self->{_writers} = \@writers;
859 }
860
861 return $self->{_writers};
862 }
863
864 =item genres()
865
866 Retrieve film genres list:
867
868 my @genres = @{ $film->genres() };
869
870 =cut
871
872 sub genresscip-perl cpan IMDB-Film 0.53 IMDB/Film/genres(). {
873 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
874 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
875
876 if($forced) {
877 my ($parser) = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
878 my (@genres);
879
880 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(MAIN_TAG)) {
881 last if $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text(). =~ /^genre/i;
882 }
883
884 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('a')) {
885 my $genre = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().;
886 last unless $tag->[1]{href} =~ m!/genre/!i;
887 last if $genre =~ /more/i;
888 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @genres, $genre;
889 }
890
891 $self->{_genres} = \@genres;
892 }
893
894 return $self->{_genres};
895 }
896
897 =item tagline()
898
899 Retrieve film tagline:
900
901 my $tagline = $film->tagline();
902
903 =cut
904
905 sub taglinescip-perl cpan IMDB-Film 0.53 IMDB/Film/tagline(). {
906 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
907 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
908
909 if($forced) {
910 my ($parser) = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
911
912 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(MAIN_TAG)) {
913 last if($parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text(). =~ /tagline/i);
914 }
915
916 $self->{_tagline} = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().(MAIN_TAG, 'a');
917 }
918
919 return $self->{_tagline};
920 }
921
922 =item plot()
923
924 Returns a movie plot:
925
926 my $plot = $film->plot;
927
928 =cut
929
930 sub plotscip-perl cpan IMDB-Film 0.53 IMDB/Film/plot(). {
931 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
932
933 return $self->{_plot};
934 }
935
936 =item storyline()
937
938 Retrieve film plot summary:
939
940 my $storyline = $film->storyline();
941
942 =cut
943
944 sub storylinescip-perl cpan IMDB-Film 0.53 IMDB/Film/storyline(). {
945 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
946 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
947
948 if($forced) {
949 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
950
951 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('h2')) {
952 last if $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text(). =~ /^storyline$/i;
953 }
954
955 my $plot = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().(MAIN_TAG, 'em');
956 $self->{_storyline} = $self->_decode_special_symbolsscip-perl cpan IMDB-Film 0.53 IMDB/Film/_decode_special_symbols().($plot);
957 }
958
959 return $self->{_storyline};
960 }
961
962 =item rating()
963
964 In scalar context returns film user rating, in array context returns
965 film rating, number of votes and info about place in TOP 250 or some other TOP and avards:
966
967 my $rating = $film->rating();
968
969 or
970
971 my($rating, $vnum, $avards) = $film->rating();
972 print "RATING: $rating ($vnum votes)";
973
974 Note, that $avards is array reference where the first elemen is a TOP info if so, and the next element is other avards - Oscar, nominations and etc
975
976 =cut
977
978 sub ratingscip-perl cpan IMDB-Film 0.53 IMDB/Film/rating(). {
979 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
980 my ($forced) = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
981
982 if($forced) {
983 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
984
985 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('div')) {
986 last if $tag->[1]{class} && $tag->[1]{class} eq 'star-box-details';
987 }
988
989 my $text = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().('/a');
990
991 my($rating, $val) = $text =~ m!(\d+\.?\d*)/10.*?(\d+,?\d*)!;
992 $val =~ s/\,// if $val;
993
994 $self->{_rating} = [$rating, $val, $self->top_infoscip-perl cpan IMDB-Film 0.53 IMDB/Film/top_info().];
995
996 unless($self->{_plot}) {
997 my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('p');
998 my $text = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().('/p');
999 $self->{_plot} = $text;
1000 }
1001 }
1002
1003 return wantarrayscip-perl cpan IMDB-Film 0.53 IMDB/Film/wantarray(). ? @{ $self->{_rating} } : $self->{_rating}[0];
1004 }
1005
1006 =item cast()
1007
1008 Retrieve film cast list each element of which is hash reference -
1009 { id => <ID>, name => <Full Name>, role => <Role> }:
1010
1011 my @cast = @{ $film->cast() };
1012
1013 <I>
1014 Note: this method retrieves a cast list first billed only!
1015 </I>
1016
1017 =cut
1018
1019 sub castscip-perl cpan IMDB-Film 0.53 IMDB/Film/cast(). {
1020 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1021 my ($forced) = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
1022
1023 if($forced) {
1024 my (@cast, $tag, $person, $id, $role);
1025 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
1026
1027 while($tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('table')) {
1028 last if $tag->[1]->{class} && $tag->[1]->{class} =~ /^cast_list$/i;
1029 }
1030 while($tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().()) {
1031 last if $tag->[0] eq 'a' && $tag->[1]{href} && $tag->[1]{href} =~ /fullcredits/i;
1032 if($tag->[0] eq 'td' && $tag->[1]{class} && $tag->[1]{class} eq 'name') {
1033 $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('a');
1034 if($tag->[1]{href} && $tag->[1]{href} =~ m#name/nm(\d+?)/#) {
1035 $person = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().;
1036 $id = $1scip-perl cpan IMDB-Film 0.53 IMDB/Film/$1.;
1037 my $text = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().('/tr');
1038 ($role) = $text =~ /.*?\s+(.*)$/;
1039 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @cast, {id => $id, name => $person, role => $role};
1040 }
1041 }
1042 }
1043
1044 $self->{_cast} = \@cast;
1045 }
1046
1047 return $self->{_cast};
1048 }
1049
1050 =item duration()
1051
1052 In the scalar context it retrieves a film duration in minutes (the first record):
1053
1054 my $duration = $film->duration();
1055
1056 In array context it retrieves all movie's durations:
1057
1058 my @durations = $film->duration();
1059
1060 =cut
1061
1062 sub durationscip-perl cpan IMDB-Film 0.53 IMDB/Film/duration(). {
1063 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1064 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
1065
1066 if($forced) {
1067
1068 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
1069 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(MAIN_TAG)) {
1070 my $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
1071 last if $text =~ /runtime:/i;
1072 }
1073 my $duration_str = $self->_decode_special_symbolsscip-perl cpan IMDB-Film 0.53 IMDB/Film/_decode_special_symbols().($parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().(MAIN_TAG, '/div'));
1074 my @runtime = splitscip-perl cpan IMDB-Film 0.53 IMDB/Film/split(). /\s+(\/|\|)\s+/, $duration_str;
1075
1076 $self->{_duration} = \@runtime;
1077 }
1078
1079 return wantarrayscip-perl cpan IMDB-Film 0.53 IMDB/Film/wantarray(). ? @{ $self->{_duration} } : $self->{_duration}->[0];
1080 }
1081
1082 =item country()
1083
1084 Retrieve film produced countries list:
1085
1086 my $countries = $film->country();
1087
1088 =cut
1089
1090 sub countryscip-perl cpan IMDB-Film 0.53 IMDB/Film/country(). {
1091 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1092 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
1093
1094 if($forced) {
1095 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
1096 while (my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(MAIN_TAG)) {
1097 last if $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text(). =~ /country/i;
1098 }
1099
1100 my (@countries);
1101 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().()) {
1102
1103 if( $tag->[0] eq 'a' && $tag->[1]{href} && $tag->[1]{href} =~ m!/country/[a-z]{2}!i ) {
1104 my $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
1105 $text =~ s/\n//g;
1106 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @countries, $text;
1107 }
1108
1109 last if $tag->[0] eq 'br';
1110 }
1111
1112 $self->{_country} = \@countries;
1113 }
1114
1115 return $self->{_country}
1116 }
1117
1118 =item language()
1119
1120 Retrieve film languages list:
1121
1122 my $languages = $film->language();
1123
1124 =cut
1125
1126 sub languagescip-perl cpan IMDB-Film 0.53 IMDB/Film/language(). {
1127 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1128 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
1129
1130 if($forced) {
1131 my (@languages, $tag);
1132 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
1133 while ($tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(MAIN_TAG)) {
1134 last if $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text(). =~ /language/i;
1135 }
1136
1137 while($tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().()) {
1138 if( $tag->[0] eq 'a' && $tag->[1]{href} && $tag->[1]{href} =~ m!/language/[a-z]{2}!i ) {
1139 my $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
1140 $text =~ s/\n//g;
1141 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @languages, $text;
1142 }
1143
1144 last if $tag->[0] eq '/div';
1145 }
1146
1147 $self->{_language} = \@languages;
1148 }
1149
1150 return $self->{_language};
1151
1152 }
1153
1154 =item also_known_as()
1155
1156 Retrieve AKA information as array, each element of which is string:
1157
1158 my $aka = $film->also_known_as();
1159
1160 print map { "$_\n" } @$aka;
1161
1162 =cut
1163
1164 sub also_known_asscip-perl cpan IMDB-Film 0.53 IMDB/Film/also_known_as(). {
1165 my CLASS_NAME $self= shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1166 unless($self->{_also_known_as}) {
1167 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
1168
1169 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(MAIN_TAG)) {
1170 my $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
1171 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("AKA: $text", 'DEBUG');
1172 last if $text =~ /^(aka|also known as)/i;
1173 }
1174
1175 my $aka = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().('span');
1176
1177 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("AKA: $aka", 'DEBUG');
1178 my @aka = ($aka);
1179 $self->{_also_known_as} = \@aka;
1180 }
1181
1182 return $self->{_also_known_as};
1183 }
1184
1185 =item trivia()
1186
1187 Retrieve a movie trivia:
1188
1189 my $trivia = $film->trivia();
1190
1191 =cut
1192
1193 sub triviascip-perl cpan IMDB-Film 0.53 IMDB/Film/trivia(). {
1194 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1195
1196 $self->{_trivia} = $self->_get_simple_propscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_simple_prop().('trivia') unless $self->{_trivia};
1197 return $self->{_trivia};
1198 }
1199
1200 =item goofs()
1201
1202 Retrieve a movie goofs:
1203
1204 my $goofs = $film->goofs();
1205
1206 =cut
1207
1208 sub goofsscip-perl cpan IMDB-Film 0.53 IMDB/Film/goofs(). {
1209 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1210
1211 $self->{_goofs} = $self->_get_simple_propscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_simple_prop().('goofs') unless($self->{_goofs});
1212 return $self->{_goofs};
1213 }
1214
1215 =item awards()
1216
1217 Retrieve a general information about movie awards like 1 win & 1 nomination:
1218
1219 my $awards = $film->awards();
1220
1221 =cut
1222
1223 sub awardsscip-perl cpan IMDB-Film 0.53 IMDB/Film/awards(). {
1224 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1225
1226 return $self->{_top_info};
1227 }
1228
1229 =item mpaa_info()
1230
1231 Return a MPAA for the specified move:
1232
1233 my mpaa = $film->mpaa_info();
1234
1235 =cut
1236
1237 sub mpaa_infoscip-perl cpan IMDB-Film 0.53 IMDB/Film/mpaa_info(). {
1238 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1239 unless($self->{_mpaa_info}) {
1240
1241 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
1242
1243 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(MAIN_TAG)) {
1244 my $text = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().(MAIN_TAG, '/a');
1245 last if $text =~ /^Motion Picture Rating/i;
1246 }
1247
1248 my $mpaa = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().('/span');
1249 $mpaa =~ s/^\)\s//;
1250 $self->{_mpaa_info} = $mpaa;
1251 }
1252
1253 return $self->{_mpaa_info};
1254 }
1255
1256 =item aspect_ratio()
1257
1258 Returns an aspect ratio of specified movie:
1259
1260 my $aspect_ratio = $film->aspect_ratio();
1261
1262 =cut
1263
1264 sub aspect_ratioscip-perl cpan IMDB-Film 0.53 IMDB/Film/aspect_ratio(). {
1265 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1266
1267 $self->{_aspect_ratio} = $self->_get_simple_propscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_simple_prop().('aspect ratio') unless $self->{_aspect_ratio};
1268
1269 return $self->{_aspect_ratio};
1270 }
1271
1272 =item summary()
1273
1274 Retrieve film user summary:
1275
1276 my $descr = $film->summary();
1277
1278 =cut
1279
1280 sub summaryscip-perl cpan IMDB-Film 0.53 IMDB/Film/summary(). {
1281 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1282 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
1283
1284 if($forced) {
1285 my($tag, $text);
1286 my($parser) = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
1287
1288 while($tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('b')) {
1289 $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
1290 last if $text =~ /^summary/i;
1291 }
1292
1293 $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().('b', 'a');
1294 $self->{_summary} = $text;
1295 }
1296
1297 return $self->{_summary};
1298 }
1299
1300 =item certifications()
1301
1302 Retrieve list of film certifications each element of which is hash reference -
1303 { country => certificate }:
1304
1305 my @cert = $film->certifications();
1306
1307 =cut
1308
1309 sub certificationsscip-perl cpan IMDB-Film 0.53 IMDB/Film/certifications(). {
1310 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1311 my $forced = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift(). || 0;
1312 my (%cert_list, $tag);
1313
1314 if($forced) {
1315 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
1316 while($tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().(MAIN_TAG)) {
1317 last if $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text(). =~ /certification/i;
1318 }
1319
1320 while($tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().()) {
1321
1322 if($tag->[0] eq 'a' && $tag->[1]{href} && $tag->[1]{href} =~ /certificates/i) {
1323 my $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
1324 $text =~ s/\n//g;
1325 my($country, $range) = splitscip-perl cpan IMDB-Film 0.53 IMDB/Film/split(). /\:/, $text;
1326 $cert_list{$country} = $range;
1327 }
1328
1329 last if $tag->[0] eq '/td';
1330 }
1331
1332 $self->{_certifications} = \%cert_list;
1333 }
1334
1335 return $self->{_certifications};
1336 }
1337
1338 =item full_plot
1339
1340 Return full movie plot.
1341
1342 my $full_plot = $film->full_plot();
1343
1344 =cut
1345
1346 sub full_plotscip-perl cpan IMDB-Film 0.53 IMDB/Film/full_plot(). {
1347 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1348
1349 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("Getting full plot ".$self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code().."; url=".$self->full_plot_urlscip-perl cpan IMDB-Film 0.53 IMDB/Film/full_plot_url().." ...", 'DEBUG');
1350 #
1351 # TODO: move all methods which needed additional connection to the IMDB.com
1352 # to the separate module.
1353 #
1354 unless($self->{_full_plot}) {
1355 my $page;
1356 $page = $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->getscip-perl cpan IMDB-Film 0.53 IMDB/Film/get().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code()..'_plot') if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
1357 unless($page) {
1358 my $url = $self->full_plot_urlscip-perl cpan IMDB-Film 0.53 IMDB/Film/full_plot_url(). . $self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code().() . '/plotsummary';
1359
1360 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("URL is $url ...", 'DEBUG');
1361
1362 $page = $self->_get_page_from_internetscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_page_from_internet().($url);
1363 unless($page) {
1364 return;
1365 }
1366
1367 $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->setscip-perl cpan IMDB-Film 0.53 IMDB/Film/set().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code()..'_plot', $page, $self->_cache_expscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache_exp().) if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
1368 }
1369
1370 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED, \$page);
1371
1372 my($text);
1373 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('p')) {
1374 if(definedscip-perl cpan IMDB-Film 0.53 IMDB/Film/defined(). $tag->[1]{class} && $tag->[1]{class} =~ /plotpar/i) {
1375 $text = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().();
1376 last;
1377 }
1378 }
1379
1380 $self->{_full_plot} = $text;
1381 }
1382
1383 return $self->{_full_plot};
1384 }
1385
1386 sub big_coverscip-perl cpan IMDB-Film 0.53 IMDB/Film/big_cover(). {
1387 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1388
1389 unless($self->{'_big_cover_url'}) {
1390 unless($self->{'_big_cover_page'}) {
1391 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED);
1392 my $regexp = '^/media/.+/tt' . $self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . '$';
1393 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('a')) {
1394 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("$regexp --> " . $tag->[1]->{href}, 'DEBUG');
1395 if($tag->[1]->{'href'} =~ m!$regexp!) {
1396 $self->{'_big_cover_page'} = $tag->[1]->{'href'};
1397 last;
1398 }
1399 }
1400 }
1401 if($self->{'_big_cover_page'}) {
1402 my $page = $self->_get_page_from_internetscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_page_from_internet().('http://' . $self->{'host'} . $self->{'_big_cover_page'});
1403 return unless $page;
1404
1405 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED, \$page);
1406 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('img')) {
1407 if($tag->[1]->{'id'} && $tag->[1]->{'id'} eq 'primary-img') {
1408 $self->{'_big_cover_url'} = $tag->[1]->{'src'};
1409 last;
1410 }
1411 }
1412 }
1413 }
1414
1415 return $self->{_big_cover_url};
1416 }
1417
1418 =item official_sites()
1419
1420 Returns a list of official sites of specified movie as array reference which contains hashes
1421 with site information - URL => Site Title:
1422
1423 my $sites = $film->official_sites();
1424 for(@$sites) {
1425 print "Site name - $_->{title}; url - $_->{url}\n";
1426 }
1427
1428 =cut
1429
1430 sub official_sitesscip-perl cpan IMDB-Film 0.53 IMDB/Film/official_sites(). {
1431 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1432
1433 unless($self->{_official_sites}) {
1434 my $page;
1435 $page = $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->getscip-perl cpan IMDB-Film 0.53 IMDB/Film/get().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . '_sites') if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
1436
1437 unless($page) {
1438 my $url = "http://". $self->{host} . "/" . $self->{query} . $self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . "/officialsites";
1439 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("URL for sites is $url ...", 'DEBUG');
1440
1441 $page = $self->_get_page_from_internetscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_page_from_internet().($url);
1442
1443 $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->setscip-perl cpan IMDB-Film 0.53 IMDB/Film/set().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code()..'_sites', $page, $self->_cache_expscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache_exp().) if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
1444 }
1445
1446
1447 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED, \$page);
1448 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().()) {
1449 last if $tag->[0] eq 'ol';
1450 }
1451
1452 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().()) {
1453 my $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
1454 if($tag->[0] eq 'a' && $tag->[1]->{href} !~ /sections/i) {
1455 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @{ $self->{_official_sites} }, { $tag->[1]->{href} => $text };
1456 }
1457
1458 last if $tag->[0] eq '/ol' or $tag->[0] eq 'hr';
1459 }
1460 }
1461
1462 return $self->{_official_sites};
1463 }
1464
1465 =item release_dates()
1466
1467 Returns a list of release dates of specified movie as array reference:
1468
1469 my $sites = $film->release_dates();
1470 for(@$sites) {
1471 print "Country - $_->{country}; release date - $_->{date}; info - $_->{info}\n";
1472 }
1473
1474 Option info contains additional information about release - DVD premiere, re-release, restored version etc
1475
1476 =cut
1477
1478 sub release_datesscip-perl cpan IMDB-Film 0.53 IMDB/Film/release_dates(). {
1479 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1480
1481 unless($self->{_release_dates}) {
1482 my $page;
1483 $page = $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->getscip-perl cpan IMDB-Film 0.53 IMDB/Film/get().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . '_dates') if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
1484
1485 unless($page) {
1486 my $url = "http://". $self->{host} . "/" . $self->{query} . $self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . "/releaseinfo";
1487 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("URL for sites is $url ...", 'DEBUG');
1488
1489 $page = $self->_get_page_from_internetscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_page_from_internet().($url);
1490 $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->setscip-perl cpan IMDB-Film 0.53 IMDB/Film/set().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code()..'_dates', $page, $self->_cache_expscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache_exp().) if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
1491 }
1492
1493 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED, \$page);
1494 # Searching header of release dates table
1495 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('th')) {
1496 last if $tag->[1]->{class} && $tag->[1]->{class} eq 'xxxx';
1497 }
1498
1499 #
1500 # The table has three columns. So we parse then one by one and grab their text
1501 #
1502 my $count = 0;
1503 my @dates = ();
1504 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().()) {
1505 last if $tag->[0] eq '/table';
1506 next unless $tag->[0] eq 'td';
1507
1508 $dates[$count] = $parser->get_trimmed_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_trimmed_text().('/td');
1509
1510 # When rish 3rd column we should store dates into object property
1511 if(++$count > 2) {
1512 $dates[2] =~ s/\)\s\(/, /g;
1513 $dates[2] =~ s/(\(|\))//g;
1514 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @{ $self->{_release_dates} }, {country => $dates[0], date => $dates[1], info => $dates[2]};
1515 $count = 0;
1516 }
1517 }
1518 }
1519
1520 return $self->{_release_dates};
1521 }
1522 =item
1523
1524 Retrieve a list of plot keywords as an array reference:
1525
1526 my $plot_keywords = $film->plot_keywords();
1527 for my $keyword (@$plot_keywords) {
1528 print "keyword: $keyword\n";
1529 }
1530
1531 =cut
1532
1533 sub plot_keywordsscip-perl cpan IMDB-Film 0.53 IMDB/Film/plot_keywords(). {
1534 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1535
1536 unless($self->{_plot_keywords}) {
1537 my $page;
1538 $page = $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->getscip-perl cpan IMDB-Film 0.53 IMDB/Film/get().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . '_keywords') if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
1539
1540 unless($page) {
1541 my $url = "http://". $self->{host} . "/" . $self->{query} . $self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code(). . "/keywords";
1542 $self->_show_messagescip-perl cpan IMDB-Film 0.53 IMDB/Film/_show_message().("URL for sites is $url ...", 'DEBUG');
1543
1544 $page = $self->_get_page_from_internetscip-perl cpan IMDB-Film 0.53 IMDB/Film/_get_page_from_internet().($url);
1545 $self->_cacheObjscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cacheObj().->setscip-perl cpan IMDB-Film 0.53 IMDB/Film/set().($self->codescip-perl cpan IMDB-Film 0.53 IMDB/Film/code()..'_keywords', $page, $self->_cache_expscip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache_exp().) if $self->_cachescip-perl cpan IMDB-Film 0.53 IMDB/Film/_cache().;
1546 }
1547
1548 my $parser = $self->_parserscip-perl cpan IMDB-Film 0.53 IMDB/Film/_parser().(FORCED, \$page);
1549
1550 my @keywords = ();
1551 while(my $tag = $parser->get_tagscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_tag().('a')) {
1552 my $text = $parser->get_textscip-perl cpan IMDB-Film 0.53 IMDB/Film/get_text().();
1553 $text = $self->_decode_special_symbolsscip-perl cpan IMDB-Film 0.53 IMDB/Film/_decode_special_symbols().($text);
1554 #$self->_show_message("*** $tag->[1]->{href} --> $text ***", 'DEBUG');
1555 pushscip-perl cpan IMDB-Film 0.53 IMDB/Film/push(). @keywords, $text if $tag->[1]->{href} && $tag->[1]->{href} =~ m#/keyword/#;
1556 }
1557
1558 $self->{_plot_keywords} = \@keywords;
1559 }
1560
1561 return $self->{_plot_keywords};
1562 }
1563
1564 =back
1565
1566 =cut
1567
1568 sub DESTROYscip-perl cpan IMDB-Film 0.53 IMDB/Film/DESTROY(). {
1569 my CLASS_NAME $self = shiftscip-perl cpan IMDB-Film 0.53 IMDB/Film/shift().;
1570 }
1571
1572 1;
1573
1574 __END__
1575
1576 =head2 Class Variables
1577
1578 =over 4
1579
1580 =item %FIELDS
1581
1582 Contains list all object's properties. See description of pragma C<fields>.
1583
1584 =item @FILM_CERT
1585
1586 Matches USA film certification notation and age.
1587
1588 =back
1589
1590 =head1 EXPORTS
1591
1592 Nothing
1593
1594 =head1 HOWTO CACTH EXCEPTIONS
1595
1596 If it's needed to get information from IMDB for a list of movies in some case it can be returned
1597 critical error:
1598
1599 [CRITICAL] Cannot retrieve page: 500 Can't read entity body ...
1600
1601 To catch an exception can be used eval:
1602
1603 for my $search_crit ("search_crit1", "search_crit2", ..., "search_critN") {
1604 my $ret;
1605 eval {
1606 $ret = new IMDB::Film(crit => "$search_crit") || print "UNKNOWN ERROR\n";
1607 };
1608
1609 if($@) {
1610 # Opsssss! We got an exception!
1611 print "EXCEPTION: $@!";
1612 next;
1613 }
1614 }
1615
1616 =head1 BUGS
1617
1618 Please, send me any found bugs by email: [email protected] or create
1619 a bug report: http://rt.cpan.org/NoAuth/Bugs.html?Dist=IMDB-Film
1620
1621 =head1 SEE ALSO
1622
1623 IMDB::Persons
1624 IMDB::BaseClass
1625 WWW::Yahoo::Movies
1626 IMDB::Movie
1627 HTML::TokeParser
1628
1629 http://videoguide.sf.net
1630
1631 =head1 AUTHOR
1632
1633 Michael Stepanov AKA nite_man ([email protected])
1634
1635 =head1 COPYRIGHT
1636
1637 Copyright (c) 2004 - 2007, Michael Stepanov.
1638 This module is free software. It may be used, redistributed and/or
1639 modified under the same terms as Perl itself.
1640
1641 =cut