line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- mode: perl; coding: utf-8 -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package WWW::NicoVideo::Scraper; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
23
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
8
|
1
|
|
|
1
|
|
912
|
use Web::Scraper; |
|
1
|
|
|
|
|
105045
|
|
|
1
|
|
|
|
|
6
|
|
9
|
1
|
|
|
1
|
|
610
|
use WWW::NicoVideo::URL; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw[Web::Scraper]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
83
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import |
13
|
|
|
|
|
|
|
{ |
14
|
2
|
|
|
2
|
|
1349
|
my $class = shift; |
15
|
2
|
|
|
|
|
3
|
my $pkg = caller; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
5
|
no strict "refs"; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
713
|
|
18
|
2
|
|
|
|
|
4
|
*{"$pkg\::scraper_entries"} = \&scraper_entries; |
|
2
|
|
|
|
|
11
|
|
19
|
2
|
|
|
|
|
3
|
*{"$pkg\::scraper"} = \&scraper; |
|
2
|
|
|
|
|
9
|
|
20
|
2
|
|
|
0
|
|
7
|
*{"$pkg\::process"} = sub { goto &process }; |
|
2
|
|
|
|
|
9
|
|
|
0
|
|
|
|
|
0
|
|
21
|
2
|
|
|
0
|
|
6
|
*{"$pkg\::process_first"} = sub { goto &process_first }; |
|
2
|
|
|
|
|
10
|
|
|
0
|
|
|
|
|
0
|
|
22
|
2
|
|
|
0
|
|
24
|
*{"$pkg\::result"} = sub { goto &result }; |
|
2
|
|
|
|
|
38
|
|
|
0
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub scraper_entries() |
26
|
|
|
|
|
|
|
{ |
27
|
|
|
|
|
|
|
scraper { |
28
|
|
|
|
|
|
|
process('//div[@class="thumb_frm"]', |
29
|
|
|
|
|
|
|
'entries[]' => scraper { |
30
|
0
|
|
|
|
|
|
process('/div/div/div/p/a/img', |
31
|
|
|
|
|
|
|
imgUrl => '@src', |
32
|
|
|
|
|
|
|
imgWidth => '@width', |
33
|
|
|
|
|
|
|
imgHeight => '@height'); |
34
|
|
|
|
|
|
|
process('/div/div/p/strong', |
35
|
|
|
|
|
|
|
lengthStr => 'TEXT', |
36
|
0
|
|
|
|
|
|
length => sub { shift->as_text =~ /(?:(\d+)分)?(\d+)秒/; |
37
|
0
|
|
|
|
|
|
$1*60 + $2 }); |
|
0
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
process('/div/div/p/strong[2]', |
39
|
|
|
|
|
|
|
numViewsStr => 'TEXT', |
40
|
0
|
|
|
|
|
|
numViews => sub { my $x = shift->as_text; |
41
|
0
|
|
|
|
|
|
$x =~ tr/,//d; |
42
|
0
|
|
|
|
|
|
$x }); |
|
0
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
process('/div/div/p/strong[3]', |
44
|
|
|
|
|
|
|
numCommentsStr => 'TEXT', |
45
|
0
|
|
|
|
|
|
numComments => sub { my $x = shift->as_text; |
46
|
0
|
|
|
|
|
|
$x =~ tr/,//d; |
47
|
0
|
|
|
|
|
|
$x }); |
|
0
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
process('/div/div[2]/p/a[@class="video"]', |
49
|
|
|
|
|
|
|
title => 'TEXT', |
50
|
0
|
|
|
|
|
|
id => sub { shift->attr("href") =~ /(\w+)$/; $1 }, |
|
0
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
url => '@href'); |
52
|
|
|
|
|
|
|
process('/div/div[2]/p', |
53
|
0
|
|
|
|
|
|
desc => sub { shift->content_array_ref->[-1] =~ /\s*(.*)/; |
54
|
0
|
|
|
|
|
|
$1 }), |
55
|
|
|
|
|
|
|
process('/div/div[2]/div/p/strong', |
56
|
0
|
|
|
|
|
|
comments => sub { my $x = shift->as_text; |
57
|
0
|
|
|
|
|
|
$x =~ s/\s+$//; |
58
|
0
|
|
|
|
|
|
$x; }); |
|
0
|
|
|
|
|
|
|
59
|
0
|
|
|
0
|
|
|
}); |
60
|
0
|
|
|
0
|
0
|
|
}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
"Ritsuko"; |