line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::IMDBtop; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
254312
|
use 5.014000; |
|
2
|
|
|
|
|
8
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
64
|
|
5
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
69
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
2010
|
use Getopt::Long; |
|
2
|
|
|
|
|
30462
|
|
|
2
|
|
|
|
|
16
|
|
8
|
2
|
|
|
2
|
|
1913
|
use IMDB::Film; |
|
2
|
|
|
|
|
293237
|
|
|
2
|
|
|
|
|
91
|
|
9
|
2
|
|
|
2
|
|
1512
|
use IMDB::Persons; |
|
2
|
|
|
|
|
6183
|
|
|
2
|
|
|
|
|
1342
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.001001'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $warned = 0; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our (%cast_cache, %cast_count); |
16
|
|
|
|
|
|
|
our ($nr, $min_count, $cache, $cache_root); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub patched_cast { |
19
|
2
|
|
|
2
|
0
|
4
|
my IMDB::Film $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
|
|
5
|
my (@cast, $tag, $person, $id, $role); |
22
|
2
|
|
|
|
|
28
|
my $parser = $self->_parser(1); |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
478
|
while($tag = $parser->get_tag('table')) { |
25
|
2
|
50
|
33
|
|
|
258943
|
last if $tag->[1]->{class} && $tag->[1]->{class} =~ /^cast_list$/i; |
26
|
|
|
|
|
|
|
} |
27
|
2
|
|
|
|
|
13
|
while($tag = $parser->get_tag()) { |
28
|
226
|
0
|
33
|
|
|
6266
|
last if $tag->[0] eq 'a' && $tag->[1]{href} && $tag->[1]{href} =~ /fullcredits/i; |
|
|
|
0
|
|
|
|
|
29
|
|
|
|
|
|
|
# if($tag->[0] eq 'td' && $tag->[1]{class} && $tag->[1]{class} eq 'name') { |
30
|
226
|
|
|
|
|
504
|
$tag = $parser->get_tag('a'); |
31
|
226
|
100
|
100
|
|
|
35713
|
if($tag->[1]{href} && $tag->[1]{href} =~ m#name/nm(\d+?)/#) { |
32
|
32
|
|
|
|
|
82
|
$person = $parser->get_text; |
33
|
32
|
|
|
|
|
2522
|
$id = $1; |
34
|
32
|
|
|
|
|
77
|
my $text = $parser->get_trimmed_text('/tr'); |
35
|
32
|
|
|
|
|
28115
|
($role) = $text =~ /\.\.\. (.*)$/; |
36
|
32
|
100
|
|
|
|
209
|
push @cast, {id => $id, name => $person, role => $role} if $person; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
# } |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
\@cast |
42
|
2
|
|
|
|
|
41
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub add_film { |
45
|
2
|
|
|
2
|
0
|
921
|
my ($crit) = @_; |
46
|
2
|
|
|
|
|
7
|
chomp $crit; |
47
|
2
|
|
|
|
|
7
|
my @args = (crit => $crit); |
48
|
2
|
50
|
|
|
|
10
|
push @args, cache => $cache if defined $cache; |
49
|
2
|
50
|
|
|
|
6
|
push @args, cache_root => $cache_root if defined $cache_root; |
50
|
2
|
|
|
|
|
37
|
my $film = IMDB::Film->new(@args); |
51
|
2
|
|
|
|
|
8192566
|
my @cast = @{ $film->cast() }; |
|
2
|
|
|
|
|
15
|
|
52
|
2
|
50
|
|
|
|
56
|
unless (@cast) { |
53
|
2
|
100
|
|
|
|
183
|
warn "Installed IMDB::Film is broken, using patched cast() method\n" unless $warned; |
54
|
2
|
|
|
|
|
7
|
$warned = 1; |
55
|
2
|
|
|
|
|
5
|
@cast = @{ patched_cast $film }; |
|
2
|
|
|
|
|
11
|
|
56
|
|
|
|
|
|
|
} |
57
|
2
|
|
|
|
|
11
|
for my $cast (@cast) { |
58
|
30
|
|
|
|
|
61
|
my ($id, $name) = ($cast->{id}, $cast->{name}); |
59
|
30
|
|
|
|
|
52
|
$cast_cache{$id} = $name; |
60
|
30
|
|
|
|
|
86
|
$cast_count{$id}++ |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub print_results { |
65
|
0
|
|
|
0
|
0
|
|
my $cnt = 0; |
66
|
0
|
|
|
|
|
|
for ( |
67
|
|
|
|
|
|
|
sort { |
68
|
|
|
|
|
|
|
$cast_count{$b} <=> $cast_count{$a} |
69
|
0
|
0
|
|
|
|
|
or $cast_cache{$a} cmp $cast_cache{$b} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
grep { |
72
|
0
|
0
|
|
|
|
|
!$min_count || $cast_count{$_} > $min_count |
73
|
|
|
|
|
|
|
} keys %cast_count) { |
74
|
0
|
0
|
0
|
|
|
|
last if $nr && $cnt++ >= $nr; |
75
|
0
|
|
|
|
|
|
say $cast_count{$_} . ' ' . $cast_cache{$_} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub run { |
80
|
0
|
|
|
0
|
0
|
|
GetOptions ( |
81
|
|
|
|
|
|
|
'n|nr=i' => \$nr, |
82
|
|
|
|
|
|
|
'm|min-count=i' => \$min_count, |
83
|
|
|
|
|
|
|
'c|cache!' => \$cache, |
84
|
|
|
|
|
|
|
'cache-root=s' => \$cache_root, |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
add_film $_ while <>; |
88
|
0
|
|
|
|
|
|
print_results |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
__END__ |