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