From 5c21c766c96f94ef0c0cf1b20158386b251dd12f Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 12 Nov 2016 18:38:03 +0200 Subject: [PATCH] Make patched_cast actually work --- lib/App/IMDBtop.pm | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) 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 { -- 2.39.2