Skip Menu |

This queue is for tickets about the IMDB-Film CPAN distribution.

Report information
The Basics
Id: 75110
Status: patched
Priority: 0/
Queue: IMDB-Film

People
Owner: Nobody in particular
Requestors: guilhem [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.51
Fixed in: (no value)



Subject: Retrieve full cast [patch attached]
Hi! The attached patch adds a method "fullcast" to retrieve to full cast list of a movie. Run "patch -p0 < fullcast.diff" in "lib/" to apply it. Cheers, -- Guilhem.
Subject: fullcast.diff
--- IMDB/Film.pm 2011-09-28 10:55:51.000000000 +0200 +++ IMDB/Film.pm 2012-02-17 14:39:18.550820300 +0100 @@ -60,6 +60,7 @@ _episodeof _summary _cast + _full_cast _directors _writers _cover @@ -145,6 +146,7 @@ _duration => [], _top_info => [], _cast => [], + _full_cast => [], ); sub _get_default_attrs { keys %_defaults } @@ -1044,6 +1046,58 @@ return $self->{_cast}; } +=item full_cast() + +Retrieve the full film cast list, each element of which is hash reference - +{ id => <ID>, name => <Full Name>, role => <Role> }: + + my @fullcast = @{ $film->full_cast() }; + +=cut + +sub full_cast { + my CLASS_NAME $self = shift; + + unless($self->{_full_cast}) { + my $page; + $page = $self->_cacheObj->get($self->code.'_cast') if $self->_cache; + unless($page) { + my $url = "http://". $self->{host} . "/" . $self->{query} . $self->code . "/fullcredits"; + + $self->_show_message("URL is $url ...", 'DEBUG'); + + $page = $self->_get_page_from_internet($url); + unless($page) { + return; + } + + $self->_cacheObj->set($self->code.'_cast', $page, $self->_cache_exp) if $self->_cache; + } + my $parser = $self->_parser(FORCED, \$page); + + my (@fullcast, $tag, $person, $id, $role); + + while($tag = $parser->get_tag('table')) { + last if $tag->[1]->{class} && $tag->[1]->{class} =~ /^cast$/i; + } + while($tag = $parser->get_tag()) { + if($tag->[0] eq 'td' && $tag->[1]{class} && $tag->[1]{class} eq 'nm') { + $tag = $parser->get_tag('a'); + if($tag->[1]{href} && $tag->[1]{href} =~ m#name/nm(\d+?)/#) { + $person = $parser->get_text; + $id = $1; + my $text = $parser->get_trimmed_text('/tr'); + ($role) = $text =~ /.*?\s+(.*)$/; + push @fullcast, {id => $id, name => $person, role => $role}; + } + } + } + + $self->{_full_cast} = \@fullcast; + } + return $self->{_full_cast}; +} + =item duration() In the scalar context it retrieves a film duration in minutes (the first record):
On Sat Feb 18 05:59:24 2012, guilhem wrote: Show quoted text
> The attached patch adds a method "fullcast" to retrieve to full cast > list of a movie.
Sorry, the method is called "full_cast" actually.