From: Marius Gavrilescu Date: Sat, 12 Nov 2016 16:38:03 +0000 (+0200) Subject: Make patched_cast actually work X-Git-Tag: 0.001001~1 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=5c21c766c96f94ef0c0cf1b20158386b251dd12f;p=app-imdbtop.git Make patched_cast actually work --- diff --git a/lib/App/IMDBtop.pm b/lib/App/IMDBtop.pm index 0eda7b2..340c612 100644 --- a/lib/App/IMDBtop.pm +++ b/lib/App/IMDBtop.pm @@ -17,33 +17,28 @@ our ($nr, $min_count, $cache, $cache_root); sub patched_cast { my IMDB::Film $self = shift; - my ($forced) = shift || 0; - - if($forced) { - my (@cast, $tag, $person, $id, $role); - my $parser = $self->_parser(1); - - while($tag = $parser->get_tag('table')) { - last if $tag->[1]->{class} && $tag->[1]->{class} =~ /^cast_list$/i; - } - while($tag = $parser->get_tag()) { - last if $tag->[0] eq 'a' && $tag->[1]{href} && $tag->[1]{href} =~ /fullcredits/i; - # if($tag->[0] eq 'td' && $tag->[1]{class} && $tag->[1]{class} eq 'name') { - $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 =~ /\.\.\. (.*)$/; - push @cast, {id => $id, name => $person, role => $role} if $person; - } - # } - } - - $self->{_cast} = \@cast; + + my (@cast, $tag, $person, $id, $role); + my $parser = $self->_parser(1); + + while($tag = $parser->get_tag('table')) { + last if $tag->[1]->{class} && $tag->[1]->{class} =~ /^cast_list$/i; + } + while($tag = $parser->get_tag()) { + last if $tag->[0] eq 'a' && $tag->[1]{href} && $tag->[1]{href} =~ /fullcredits/i; + # if($tag->[0] eq 'td' && $tag->[1]{class} && $tag->[1]{class} eq 'name') { + $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 =~ /\.\.\. (.*)$/; + push @cast, {id => $id, name => $person, role => $role} if $person; + } + # } } - return $self->{_cast}; + \@cast } sub add_film {