line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: download novel /bbs thread |
2
|
|
|
|
|
|
|
package Novel::Robot; |
3
|
2
|
|
|
2
|
|
58722
|
use strict; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
52
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
39
|
|
5
|
2
|
|
|
2
|
|
498
|
use utf8; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
10
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
436
|
use Novel::Robot::Parser; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
20
|
|
8
|
2
|
|
|
2
|
|
871
|
use Novel::Robot::Packer; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
22
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.42; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
2
|
|
|
2
|
0
|
165
|
my ( $self, %opt ) = @_; |
14
|
2
|
|
50
|
|
|
15
|
$opt{max_process_num} ||= 3; |
15
|
2
|
|
100
|
|
|
8
|
$opt{type} ||= 'html'; |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
17
|
my $parser = Novel::Robot::Parser->new( %opt ); |
18
|
2
|
|
|
|
|
16
|
my $packer = Novel::Robot::Packer->new( %opt ); |
19
|
2
|
|
|
|
|
16
|
my $browser = $parser->{browser}; |
20
|
2
|
|
|
|
|
17
|
bless { %opt, parser => $parser, packer => $packer, browser => $browser }, |
21
|
|
|
|
|
|
|
__PACKAGE__; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub set_parser { |
25
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $site ) = @_; |
26
|
0
|
|
|
|
|
0
|
$self->{site} = $self->{parser}->detect_site( $site ); |
27
|
0
|
|
|
|
|
0
|
$self->{parser} = Novel::Robot::Parser->new( %$self ); |
28
|
0
|
|
|
|
|
0
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub set_packer { |
32
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $type ) = @_; |
33
|
0
|
|
|
|
|
0
|
$self->{type} = $type; |
34
|
0
|
|
|
|
|
0
|
$self->{packer} = Novel::Robot::Packer->new( %$self ); |
35
|
0
|
|
|
|
|
0
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get_novel { |
39
|
1
|
|
|
1
|
0
|
14
|
my ( $self, $index_url, %o ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
10
|
my $novel_ref = $self->{parser}->get_novel_ref( $index_url, %o ); |
42
|
1
|
50
|
|
|
|
5
|
return unless ( $novel_ref ); |
43
|
1
|
50
|
|
|
|
3
|
return unless ( @{ $novel_ref->{item_list} } ); |
|
1
|
|
|
|
|
3
|
|
44
|
1
|
50
|
|
|
|
2
|
return unless ( grep { $_->{content} } @{ $novel_ref->{item_list} } ); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
3
|
|
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
5
|
while( ! $novel_ref->{item_list}[-1]{content}){ |
47
|
0
|
|
|
|
|
0
|
pop @{$novel_ref->{item_list}}; |
|
0
|
|
|
|
|
0
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $last_item_num = |
51
|
1
|
|
|
|
|
5
|
scalar( @{ $novel_ref->{item_list} } ) > 0 |
52
|
|
|
|
|
|
|
? $novel_ref->{item_list}[-1]{id} |
53
|
1
|
50
|
0
|
|
|
3
|
: ( $novel_ref->{item_num} || scalar( @{ $novel_ref->{item_list} } ) ); |
54
|
|
|
|
|
|
|
#print "\rlast_item_num: $last_item_num\n" if ( $o{verbose} ); |
55
|
1
|
50
|
|
|
|
3
|
print "\nlast_item_num: $last_item_num\n" if ( $o{verbose} ); |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
15
|
$self->{packer}->format_item_output( $novel_ref, \%o ); |
58
|
1
|
|
|
|
|
6
|
my $r = $self->{packer}->main( $novel_ref, %o ); |
59
|
1
|
50
|
|
|
|
12
|
return wantarray ? ( $r, $novel_ref ) : $r; |
60
|
|
|
|
|
|
|
} ## end sub get_novel |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub split_index { |
63
|
0
|
|
|
0
|
0
|
|
my $s = $_[-1]; |
64
|
0
|
0
|
|
|
|
|
return ( $s, $s ) if ( $s =~ /^\d+$/ ); |
65
|
0
|
0
|
|
|
|
|
if ( $s =~ /^\d*-\d*$/ ) { |
66
|
0
|
|
|
|
|
|
my ( $min, $max ) = split '-', $s; |
67
|
0
|
|
|
|
|
|
return ( $min, $max ); |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
return; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 NAME |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Novel::Robot - Download novel /bbs thread |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |