| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::FetchStory::Fetcher::SSHGPromptfest; |
|
2
|
|
|
|
|
|
|
$WWW::FetchStory::Fetcher::SSHGPromptfest::VERSION = '0.2602'; |
|
3
|
1
|
|
|
1
|
|
230878
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
47
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
86
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
WWW::FetchStory::Fetcher::SSHGPromptfest - fetching module for WWW::FetchStory |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 VERSION |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
version 0.2602 |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This is the SSHGPromptfest story-fetching plugin for WWW::FetchStory. |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
|
18
|
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
25
|
use parent qw(WWW::FetchStory::Fetcher::LiveJournal); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
9
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 METHODS |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 info |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Information about the fetcher. |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$info = $self->info(); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub info { |
|
32
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $info = "(http://sshg_promptfest.livejournal.com/) Severus Snape/Hermione Granger fiction exchange comm."; |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return $info; |
|
37
|
|
|
|
|
|
|
} # info |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 priority |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
The priority of this fetcher. Fetchers with higher priority |
|
42
|
|
|
|
|
|
|
get tried first. This is useful where there may be a generic |
|
43
|
|
|
|
|
|
|
fetcher for a particular site, and then a more specialized fetcher |
|
44
|
|
|
|
|
|
|
for particular sections of a site. For example, there may be a |
|
45
|
|
|
|
|
|
|
generic LiveJournal fetcher, and then refinements for particular |
|
46
|
|
|
|
|
|
|
LiveJournal community, such as the sshg_exchange community. |
|
47
|
|
|
|
|
|
|
This works as either a class function or a method. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
This must be overridden by the specific fetcher class. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$priority = $self->priority(); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$priority = WWW::FetchStory::Fetcher::priority($class); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub priority { |
|
58
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return 2; |
|
61
|
|
|
|
|
|
|
} # priority |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 allow |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
If this fetcher can be used for the given URL, then this returns |
|
66
|
|
|
|
|
|
|
true. |
|
67
|
|
|
|
|
|
|
This must be overridden by the specific fetcher class. |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
if ($obj->allow($url)) |
|
70
|
|
|
|
|
|
|
{ |
|
71
|
|
|
|
|
|
|
.... |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub allow { |
|
77
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
78
|
0
|
|
|
|
|
|
my $url = shift; |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
return ($url =~ /sshg[-_]promptfest\.livejournal\.com/); |
|
81
|
|
|
|
|
|
|
} # allow |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 Private Methods |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 parse_toc |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Parse the table-of-contents file. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
%info = $self->parse_toc(content=>$content, |
|
90
|
|
|
|
|
|
|
url=>$url, |
|
91
|
|
|
|
|
|
|
urls=>\@urls); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This should return a hash containing: |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item chapters |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
An array of URLs for the chapters of the story. In the case where the |
|
100
|
|
|
|
|
|
|
story only takes one page, that will be the chapter. |
|
101
|
|
|
|
|
|
|
In the case where multiple URLs have been passed in, it will be those URLs. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item title |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
The title of the story. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=back |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
It may also return additional information, such as Summary. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub parse_toc { |
|
114
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
115
|
0
|
|
|
|
|
|
my %args = ( |
|
116
|
|
|
|
|
|
|
url=>'', |
|
117
|
|
|
|
|
|
|
content=>'', |
|
118
|
|
|
|
|
|
|
@_ |
|
119
|
|
|
|
|
|
|
); |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $content = $args{content}; |
|
122
|
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
my %info = (); |
|
124
|
0
|
|
|
|
|
|
$info{url} = $args{url}; |
|
125
|
0
|
|
|
|
|
|
$info{toc_first} = 1; |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my $title = $self->parse_title(%args); |
|
128
|
0
|
|
|
|
|
|
$title =~ s/sshg_promptfest\s*//; |
|
129
|
0
|
|
|
|
|
|
$info{title} = $title; |
|
130
|
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $summary = $self->parse_summary(%args); |
|
132
|
0
|
|
|
|
|
|
$summary =~ s/"/'/g; |
|
133
|
0
|
|
|
|
|
|
$info{summary} = $summary; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my $author = $self->parse_author(%args); |
|
136
|
0
|
|
|
|
|
|
$info{author} = $author; |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
$info{characters} = "Hermione Granger, Severus Snape"; |
|
139
|
0
|
|
|
|
|
|
$info{universe} = 'Harry Potter'; |
|
140
|
0
|
|
|
|
|
|
$info{recipient} = $self->parse_recipient(%args); |
|
141
|
0
|
|
|
|
|
|
$info{chapters} = $self->parse_chapter_urls(%args); |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
return %info; |
|
144
|
|
|
|
|
|
|
} # parse_toc |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 parse_chapter_urls |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Figure out the URLs for the chapters of this story. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
|
151
|
|
|
|
|
|
|
sub parse_chapter_urls { |
|
152
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
153
|
0
|
|
|
|
|
|
my %args = ( |
|
154
|
|
|
|
|
|
|
url=>'', |
|
155
|
|
|
|
|
|
|
content=>'', |
|
156
|
|
|
|
|
|
|
@_ |
|
157
|
|
|
|
|
|
|
); |
|
158
|
0
|
|
|
|
|
|
my $content = $args{content}; |
|
159
|
0
|
|
|
|
|
|
my $sid = $args{sid}; |
|
160
|
0
|
|
|
|
|
|
my @chapters = (); |
|
161
|
0
|
0
|
|
|
|
|
if (defined $args{urls}) |
|
162
|
|
|
|
|
|
|
{ |
|
163
|
0
|
|
|
|
|
|
@chapters = @{$args{urls}}; |
|
|
0
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
for (my $i = 0; $i < @chapters; $i++) |
|
165
|
|
|
|
|
|
|
{ |
|
166
|
0
|
|
|
|
|
|
$chapters[$i] = sprintf('%s?format=light', $chapters[$i]); |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
} |
|
169
|
0
|
0
|
|
|
|
|
if (@chapters == 1) |
|
170
|
|
|
|
|
|
|
{ |
|
171
|
0
|
|
|
|
|
|
while ($content =~ m/href=["'](http:\/\/sshg[-_]pf[-_](?:mod|fanwork)\.livejournal\.com\/\d+.html)/sg) |
|
172
|
|
|
|
|
|
|
{ |
|
173
|
0
|
|
|
|
|
|
my $ch_url = $1; |
|
174
|
0
|
0
|
|
|
|
|
warn "chapter=$ch_url\n" if ($self->{verbose} > 1); |
|
175
|
0
|
|
|
|
|
|
push @chapters, "${ch_url}?format=light"; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
return \@chapters; |
|
180
|
|
|
|
|
|
|
} # parse_chapter_urls |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; # End of WWW::FetchStory::Fetcher::SSHGPromptfest |
|
183
|
|
|
|
|
|
|
__END__ |