| 1 | package WWW::FetchStory::Fetcher::AO3; | ||||||||||||||||||||||||||||
| 2 | 1 | $WWW::FetchStory::Fetcher::AO3::VERSION = '0.2004'; | |||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | WWW::FetchStory::Fetcher::AO3 - fetching module for WWW::FetchStory | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 VERSION | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | version 0.2004 | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | This is the AO3 story-fetching plugin for WWW::FetchStory. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | our @ISA = qw(WWW::FetchStory::Fetcher); | |||||||||||||||||||||||||||
| 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | my $info = "http://www.archiveofourown.org AO3 General fanfic archive"; | |||||||||||||||||||||||||||
| 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 AO3 fetcher, and then refinements for particular | ||||||||||||||||||||||||||||
| 46 | AO3 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 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
priority: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | return 1; | |||||||||||||||||||||||||||
| 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
allow: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 0 | my $url = shift; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | return ($url =~ /archiveofourown\.org/ || $url =~ /ao3\.org/); | ||||||||||||||||||||||||||
|
Condition0%0/3
$url =~ /archiveofourown\.org/ || $url =~ /ao3\.org/
MC/DC0%0/2
$url =~ /archiveofourown\.org/ || $url =~ /ao3\.org/
$url =~ /archiveofourown\.org/
$url =~ /ao3\.org/
Truth table0%0/3
A || B
A= $url =~ /archiveofourown\.org/B= $url =~ /ao3\.org/
| |||||||||||||||||||||||||||||
| 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse_toc: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 0 | my %args = ( | |||||||||||||||||||||||||||
| 116 | url=>'', | ||||||||||||||||||||||||||||
| 117 | content=>'', | ||||||||||||||||||||||||||||
| 118 | @_ | ||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | my $content = $args{content}; | |||||||||||||||||||||||||||
| 122 | 0 | my %info = (); | |||||||||||||||||||||||||||
| 123 | 0 | $info{url} = $args{url}; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | my $sid=''; | |||||||||||||||||||||||||||
| 126 | 0 | ▶ | if ($args{url} =~ m#archiveofourown.org/works/(\d+)#) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||
| 128 | 0 | $sid = $1; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | else | ||||||||||||||||||||||||||||
| 131 | { | ||||||||||||||||||||||||||||
| 132 | 0 | print STDERR "did not find SID for $args{url}"; | |||||||||||||||||||||||||||
| 133 | 0 | return $self->SUPER::parse_toc(%args); | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | $info{title} = $self->parse_title(%args); | |||||||||||||||||||||||||||
| 137 | 0 | $info{author} = $self->parse_author(%args); | |||||||||||||||||||||||||||
| 138 | 0 | $info{summary} = $self->parse_summary(%args); | |||||||||||||||||||||||||||
| 139 | 0 | $info{characters} = $self->parse_characters(%args); | |||||||||||||||||||||||||||
| 140 | 0 | $info{universe} = $self->parse_universe(%args); | |||||||||||||||||||||||||||
| 141 | 0 | $info{category} = $self->parse_category(%args); | |||||||||||||||||||||||||||
| 142 | 0 | $info{rating} = $self->parse_rating(%args); | |||||||||||||||||||||||||||
| 143 | 0 | $info{chapters} = $self->parse_chapter_urls(%args, sid=>$sid); | |||||||||||||||||||||||||||
| 144 | #$info{epub_url} = $self->parse_epub_url(%args, sid=>$sid); | ||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ($info{epub_url}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||
| 147 | 0 | $info{wordcount} = $self->parse_wordcount(%args); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | return %info; | |||||||||||||||||||||||||||
| 151 | } # parse_toc | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head2 parse_chapter_urls | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Figure out the URLs for the chapters of this story. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||||||||||
| 158 | sub parse_chapter_urls { | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse_chapter_urls: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 160 | 0 | my %args = ( | |||||||||||||||||||||||||||
| 161 | urls=>undef, | ||||||||||||||||||||||||||||
| 162 | content=>'', | ||||||||||||||||||||||||||||
| 163 | @_ | ||||||||||||||||||||||||||||
| 164 | ); | ||||||||||||||||||||||||||||
| 165 | 0 | my $content = $args{content}; | |||||||||||||||||||||||||||
| 166 | 0 | my $sid = $args{sid}; | |||||||||||||||||||||||||||
| 167 | 0 | my @chapters = (); | |||||||||||||||||||||||||||
| 168 | 0 | ▶ | if (defined $args{urls}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | { | ||||||||||||||||||||||||||||
| 170 | 0 | @chapters = @{$args{urls}}; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if (@chapters == 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@chapters == 1 and $content =~ m[href="(/downloads/[-\/\w]+/$sid/[^.]+\.html)]
MC/DC0%0/2
@chapters == 1 and $content =~ m[href="(/downloads/[-\/\w]+/$sid/[^.]+\.html)]
@chapters == 1
$content =~ m[href="(/downloads/[-\/\w]+/$sid/[^.]+\.html)]
Truth table0%0/3
A and B
A= @chapters == 1B= $content =~ m[href="(/downloads/[-\/\w]+/$sid/[^.]+\.html)]
| |||||||||||||||||||||||||||||
| 173 | and $content =~ m!href="(/downloads/[-\/\w]+/$sid/[^.]+\.html)!) | ||||||||||||||||||||||||||||
| 174 | { | ||||||||||||||||||||||||||||
| 175 | 0 | @chapters = ("http://archiveofourown.org$1"); | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | return \@chapters; | |||||||||||||||||||||||||||
| 179 | } # parse_chapter_urls | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =head2 parse_epub_url | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | Figure out the URL for the EPUB version of this story. | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =cut | ||||||||||||||||||||||||||||
| 186 | sub parse_epub_url { | ||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse_epub_url: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | 0 | my %args = ( | |||||||||||||||||||||||||||
| 189 | url=>'', | ||||||||||||||||||||||||||||
| 190 | content=>'', | ||||||||||||||||||||||||||||
| 191 | @_ | ||||||||||||||||||||||||||||
| 192 | ); | ||||||||||||||||||||||||||||
| 193 | 0 | my $content = $args{content}; | |||||||||||||||||||||||||||
| 194 | 0 | my $sid = $args{sid}; | |||||||||||||||||||||||||||
| 195 | 0 | my $epub_url = ''; | |||||||||||||||||||||||||||
| 196 | 0 | ▶ | if ($content =~ m!href="(/downloads/[-\/\w]+/$sid/[^.]+\.epub)!) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||
| 198 | 0 | $epub_url = ("http://archiveofourown.org$1"); | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | return $epub_url; | |||||||||||||||||||||||||||
| 202 | } # parse_epub_url | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =head2 parse_title | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | Get the title. | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =cut | ||||||||||||||||||||||||||||
| 209 | sub parse_title { | ||||||||||||||||||||||||||||
| 210 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse_title: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 211 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | my $content = $args{content}; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | my $title = ''; | |||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ($content =~ m!<h2 class="title heading">\s*([^<]*)</h2>!s) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||
| 218 | 0 | $title = $1; | |||||||||||||||||||||||||||
| 219 | 0 | $title =~ s/\s*$//s; # remove any trailing whitespace | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | elsif ($content =~ m!<h1>([^<]*)</h1>!) | ||||||||||||||||||||||||||||
| 222 | { | ||||||||||||||||||||||||||||
| 223 | 0 | $title = $1; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | else | ||||||||||||||||||||||||||||
| 226 | { | ||||||||||||||||||||||||||||
| 227 | 0 | $title = $self->SUPER::parse_title(%args); | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | 0 | return $title; | |||||||||||||||||||||||||||
| 230 | } # parse_title | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =head2 parse_author | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | Get the author. | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =cut | ||||||||||||||||||||||||||||
| 237 | sub parse_author { | ||||||||||||||||||||||||||||
| 238 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse_author: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 239 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 0 | my $content = $args{content}; | |||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | say STDERR "start of parse_author"; | |||||||||||||||||||||||||||
| 244 | 0 | my $author = ''; | |||||||||||||||||||||||||||
| 245 | 0 | ▶ | if ($content =~ m! href="/users/\w+/pseuds/\w+">([^<]+)</a>!) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | { | ||||||||||||||||||||||||||||
| 247 | 0 | $author = $1; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | else | ||||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||||
| 251 | 0 | $author = $self->SUPER::parse_author(%args); | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | 0 | $author =~ s/_/ /g; | |||||||||||||||||||||||||||
| 254 | 0 | return $author; | |||||||||||||||||||||||||||
| 255 | } # parse_author | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | =head2 parse_summary | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | Get the summary. | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =cut | ||||||||||||||||||||||||||||
| 262 | sub parse_summary { | ||||||||||||||||||||||||||||
| 263 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse_summary: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 264 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 0 | my $content = $args{content}; | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | my $summary = ''; | |||||||||||||||||||||||||||
| 269 | 0 | ▶ | if ($content =~ m!<h3[^>]*>Summary:</h3>\s*<blockquote class="userstuff"><p>([^<]+)</p></blockquote>!s) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | { | ||||||||||||||||||||||||||||
| 271 | 0 | $summary = $1; | |||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | else | ||||||||||||||||||||||||||||
| 274 | { | ||||||||||||||||||||||||||||
| 275 | 0 | $summary = $self->SUPER::parse_summary(%args); | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | # AO3 tends to have messy HTML stuff stuck in the summary | ||||||||||||||||||||||||||||
| 278 | 0 | $summary =~ s!<[a-zA-Z]>!!g; | |||||||||||||||||||||||||||
| 279 | 0 | $summary =~ s!</[a-zA-Z]>!!g; | |||||||||||||||||||||||||||
| 280 | 0 | $summary =~ s!<\w+>!!g; | |||||||||||||||||||||||||||
| 281 | 0 | $summary =~ s!</\w+>!!g; | |||||||||||||||||||||||||||
| 282 | 0 | $summary =~ s!'!'!g; | |||||||||||||||||||||||||||
| 283 | 0 | $summary =~ s!'!'!g; | |||||||||||||||||||||||||||
| 284 | 0 | return $summary; | |||||||||||||||||||||||||||
| 285 | } # parse_summary | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | =head2 parse_wordcount | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | Get the wordcount. | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | =cut | ||||||||||||||||||||||||||||
| 292 | sub parse_wordcount { | ||||||||||||||||||||||||||||
| 293 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse_wordcount: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 294 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 0 | my $content = $args{content}; | |||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 0 | my $words = ''; | |||||||||||||||||||||||||||
| 299 | 0 | ▶ | if ($content =~ m!\((\d+) words\)!m) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | { | ||||||||||||||||||||||||||||
| 301 | 0 | $words = $1; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | 0 | return $words; | |||||||||||||||||||||||||||
| 304 | } # parse_wordcount | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | =head2 parse_characters | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | Get the characters. | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | =cut | ||||||||||||||||||||||||||||
| 311 | sub parse_characters { | ||||||||||||||||||||||||||||
| 312 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse_characters: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 313 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 0 | my $content = $args{content}; | |||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 0 | my $characters = ''; | |||||||||||||||||||||||||||
| 318 | 0 | ▶ | if ($content =~ m!<dd class="character tags">(.*?)</dd>!s) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 319 | { | ||||||||||||||||||||||||||||
| 320 | # multiple characters inside links | ||||||||||||||||||||||||||||
| 321 | 0 | my $str = $1; | |||||||||||||||||||||||||||
| 322 | 0 | my @chars = (); | |||||||||||||||||||||||||||
| 323 | 0 | ▶ | while ($str =~ m!([^><]+)</a>!g) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | { | ||||||||||||||||||||||||||||
| 325 | 0 | push @chars, $1; | |||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | 0 | $characters = join(', ', @chars); | |||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | elsif ($content =~ m!^Characters: (.*?)$!m) | ||||||||||||||||||||||||||||
| 330 | { | ||||||||||||||||||||||||||||
| 331 | 0 | $characters = $1; | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | else | ||||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||
| 335 | 0 | $characters = $self->SUPER::parse_characters(%args); | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | # Remove the (Universe) part of the characters | ||||||||||||||||||||||||||||
| 338 | 0 | $characters =~ s!\s*\([^)]+\)!!g; | |||||||||||||||||||||||||||
| 339 | 0 | return $characters; | |||||||||||||||||||||||||||
| 340 | } # parse_characters | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | =head2 parse_universe | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | Get the universe. | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | =cut | ||||||||||||||||||||||||||||
| 347 | sub parse_universe { | ||||||||||||||||||||||||||||
| 348 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse_universe: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 349 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 0 | my $content = $args{content}; | |||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 0 | my $universe = ''; | |||||||||||||||||||||||||||
| 354 | 0 | ▶ | if ($content =~ m!Fandom: <a href="https?://archiveofourown\.org/tags/.*?">(.*?)</a>!) | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 355 | { | ||||||||||||||||||||||||||||
| 356 | 0 | $universe = $1; | |||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | elsif ($content =~ m!^Fandom: (<a href="https?://archiveofourown.org/tags/.*?,.*?)$!m) | ||||||||||||||||||||||||||||
| 359 | { | ||||||||||||||||||||||||||||
| 360 | 0 | my $fandoms = $1; | |||||||||||||||||||||||||||
| 361 | 0 | my @fds = split(/,/, $fandoms); | |||||||||||||||||||||||||||
| 362 | 0 | my @universes = (); | |||||||||||||||||||||||||||
| 363 | 0 | foreach my $fd (@fds) | |||||||||||||||||||||||||||
| 364 | { | ||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if ($fd =~ m!<a href="https?://archiveofourown.org/tags/.*?">(.*?)</a>!m) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | { | ||||||||||||||||||||||||||||
| 367 | 0 | push @universes, $1; | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||
| 370 | 0 | $universe = join(', ', @universes); | |||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | elsif ($content =~ m!^Fandom: <a href="https?://archiveofourown.org/tags/.*?">(.*?)</a>$!m) | ||||||||||||||||||||||||||||
| 373 | { | ||||||||||||||||||||||||||||
| 374 | 0 | $universe = $1; | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | else | ||||||||||||||||||||||||||||
| 377 | { | ||||||||||||||||||||||||||||
| 378 | 0 | $universe = $self->SUPER::parse_universe(%args); | |||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | # Minor adjustments to AO3 tags | ||||||||||||||||||||||||||||
| 381 | 0 | ▶ | if ($universe =~ m!Harry Potter - J\. K\. Rowling!) | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 382 | { | ||||||||||||||||||||||||||||
| 383 | 0 | $universe =~ s/\s*-\s*J\. K\. Rowling//; | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | elsif ($universe =~ m!(Doctor Who)!) | ||||||||||||||||||||||||||||
| 386 | { | ||||||||||||||||||||||||||||
| 387 | 0 | $universe = $1; | |||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | elsif ($universe =~ m!Blake&#39;s 7!) | ||||||||||||||||||||||||||||
| 390 | { | ||||||||||||||||||||||||||||
| 391 | 0 | $universe = 'Blakes 7'; | |||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | 0 | return $universe; | |||||||||||||||||||||||||||
| 394 | } # parse_universe | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | =head2 parse_category | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | Get the category. | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | =cut | ||||||||||||||||||||||||||||
| 401 | sub parse_category { | ||||||||||||||||||||||||||||
| 402 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
parse_category: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 403 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 0 | my $content = $args{content}; | |||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 0 | my $category = ''; | |||||||||||||||||||||||||||
| 408 | 0 | ▶ | if ($content =~ m!<dd class="freeform tags">(.*?)</dd>!s) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 409 | { | ||||||||||||||||||||||||||||
| 410 | # multiple categories inside links | ||||||||||||||||||||||||||||
| 411 | 0 | my $str = $1; | |||||||||||||||||||||||||||
| 412 | 0 | my @cats = (); | |||||||||||||||||||||||||||
| 413 | 0 | ▶ | while ($str =~ m!([^><]+)</a>!g) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | { | ||||||||||||||||||||||||||||
| 415 | 0 | push @cats, $1; | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | 0 | $category = join(', ', @cats); | |||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | elsif ($content =~ m!Additional Tags:\s*</dt>\s*<dd class="freeform tags">\s*<ul[^>]*>\s*(.*?)\s*</ul>!s) | ||||||||||||||||||||||||||||
| 420 | { | ||||||||||||||||||||||||||||
| 421 | 0 | my $categories = $1; | |||||||||||||||||||||||||||
| 422 | 0 | my @cats = split(/<li>/, $categories); | |||||||||||||||||||||||||||
| 423 | 0 | my @categories = (); | |||||||||||||||||||||||||||
| 424 | 0 | foreach my $cat (@cats) | |||||||||||||||||||||||||||
| 425 | { | ||||||||||||||||||||||||||||
| 426 | 0 | ▶ | if ($cat =~ m!class="tag">([^<]+)</a>!) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | { | ||||||||||||||||||||||||||||
| 428 | 0 | push @categories, $1; | |||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||
| 431 | 0 | $category = join(', ', @categories); | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | else | ||||||||||||||||||||||||||||
| 434 | { | ||||||||||||||||||||||||||||
| 435 | 0 | $category = $self->SUPER::parse_category(%args); | |||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||
| 437 | 0 | return $category; | |||||||||||||||||||||||||||
| 438 | } # parse_category | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 1 | 1; # End of WWW::FetchStory::Fetcher::AO3 | |||||||||||||||||||||||||||
| 441 | __END__ | ||||||||||||||||||||||||||||