The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

IMDB.pm - module to fetch movie info from www.imdb.com

DESCRIPTION

This is a module that uses LWP and HTML::TokeParser to parse the web page for the requested movie. You can use an IMDB identification number or the name of the movie. IMDB.pm will try to return the best match.

SYNOPSIS

  use strict;
  use IMDB::Movie;

  my $movie = IMDB::Movie->new(92610);
  print join("|",
    $movie->title, 
    $movie->id, 
    $movie->year, 
    join(';',@{$movie->director}),
    join(';',@{$movie->writer}),
    join(';',@{$movie->genres}),
    $movie->user_rating,
    $movie->img,
  ), "\n";

  sleep 5;

  # now more compatible with HTML::Template!
  $tmpl->param($movie->as_HTML_Template);

METHODS

new
  my $movie_by_id = IMDB::Movie->new(92610);

  my $movie_by_title = IMDB::Movie->new('Bad Taste');

Instantiates the object and fetches the movie. IMDB::Movie prefers the IMDB identification number, but you can pass the name of the movie with moderate success. Note that this causes an extra page fetch as IMDB::Movie parses the search results.

You can also specify which 'site' you want to search:

  my $movie = IMDB::Movie->new('Alien','uk');

This will search uk.imdb.com instead of www.imdb.com, the default.

title
  my $title = $movie->title;

Returns the IMDB given title of this movie.

id
  my $id = $movie->id;

Returns the IMDB id of this movie.

year
  my $year = $movie->year;

Returns the year the movie was released.

director
  my @director = @{$movie->director};

Returns an anonymous array reference of director names.

directors
  my %director = %{$movie->directors};
  for my $id (keys %director) {
     print $director{$id}{first_name};
     print $director{$id}{last_name};
  }

Returns an anonymous hash reference whose keys are IMDB name id's and whose values are anonymous hash references containing first and last name key/value pairs.

writer
  my @writer = @{$movie->writer};

Returns an anonymous array reference of writer names.

writers
  my %writer = %{$movie->writers};
  for my $id (keys %writer) {
     print $writer{$id}{first_name};
     print $writer{$id}{last_name};
  }

Return an anonymous hash reference whose keys are IMDB name id's and whose values are anonymous hash references containing first and last name key/value pairs.

cast
  my %cast = %{$movie->cast};
  for my $id (keys %cast) {
     print $cast{$id}{first_name};
     print $cast{$id}{last_name};
  }

Return an anonymous hash reference whose keys are IMDB name id's and whose values are anonymous hash references containing first and last name key/value pairs.

This is for the First Billed cast only, that is, the module parses out the name from the first page. Possibly in the future i will parse out the entire crew, but it's doubtful.

genres
  my @genres = @{$movie->genres};

Returns an anonymous array reference of genre names.

user_rating
  my $user_rating = $movie->user_rating;

Returns the current IMDB user rating as is.

img
  my $img = $movie->img;

Returns the url of the image used for this Movie at imdb.com

matches
  my @match = @{$movie->matches};

Returns a list of hashes (LoH) containing 'id' and 'title' key/value pairs for all title matches returned when a seach by title was performed. For example:

  use IMDB::Movie;
  use CGI qw(:standard);
  my $movie = IMDB::Movie->new('Terminator');
  my @match = @{$movie->matches};

  if (@match) {
     print (
        p('The following matches were found:'),
        ol(
           li([ map
              a(
                 {href => "http://imdb.com/title/tt$_->{id}"},
                 $_->{title}
              ), @match
           ])
        ),
     );
  }

will produce an HTML ordered list of anchored links.

as_HTML_Template
  my %t_movie = $movie->as_HTML_Template;

This simply returns a hash that is a clone of the IMDB::Movie object. The only difference between the clone and the original is the clone's directors, writers, and genres methods return HTML::Template ready data structures. Just use Data::Dumper and see the ouput for yourself - if you use HTML::Template, you'll know what to do with it.

BUGS

If you have found a bug, typo, etc. please visit Best Practical Solution's CPAN bug tracker at http://rt.cpan.org:

<http://rt.cpan.org/NoAuth/Bugs.html?Dist=IMDB-Movie>

or send mail to <bug-IMDB-Movie#rt.cpan.org>

(you got this far ... you can figure out how to make that a valid address ... and note that i won't respond to bugs sent to my personal address any longer)

AUTHOR

Jeffrey Hayes Anderson

CREDITS

Various suggestions and typo spottings:

   - Danilo Aghemo
   - ArteQ 2
   - Marvin Baschangel
   - V. Ray Krebs III
   - Codrut C. Racosanu

DISCLAIMER

This module should be used VERY SPARSLEY. The good people at the Internet Movie Database provide access to their websites for free, and i do not want this module to be used in an irresponsible manor.

Also, screen-scraping a web site does not make for a long living application. Any changes to IMDB's design could potentially break this module. I give no garuantee that i will maintain this module, but i will garuantee that i may just delete this module with no notice.

COPYRIGHT

Movie Data Copyright (c) 1990-2004 Internet Movie Database Inc.

Module Copyright (c) 2004 Jeffrey Hayes Anderson.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.