$WWW::FetchStory::Fetcher::HPAdultFanfiction::VERSION
=
'0.2501'
;
sub
new {
my
$class
=
shift
;
my
$self
=
$class
->SUPER::new(
@_
);
$self
->{wget} .=
" --user-agent=''"
;
return
(
$self
);
}
sub
info {
my
$self
=
shift
;
return
$info
;
}
sub
priority {
my
$class
=
shift
;
return
2;
}
sub
allow {
my
$self
=
shift
;
my
$url
=
shift
;
return
(
$url
=~ /hp\.adultfanfiction\.net/);
}
sub
extract_story {
my
$self
=
shift
;
my
%args
= (
content
=>
''
,
title
=>
''
,
@_
);
my
$content
=
$args
{content};
my
$title
=
$args
{title};
my
$chapter
=
$self
->parse_ch_title(
%args
);
warn
"chapter=$chapter\n"
if
(
$self
->{verbose} > 1);
my
$author
=
$self
->parse_author(
%args
);
warn
"author=$author\n"
if
(
$self
->{verbose} > 1);
my
$story
=
''
;
if
(
$content
=~ m!<td colspan=
"3"
bgcolor=
"F4EBCC"
>\s*<font color=
"#003333"
>Disclaimer:[^<]+</font>\s*</td>\s*</
tr
>\s*<
tr
>\s*<td colspan=
"3"
>\s*<p>
 
;</p>\s*</td>\s*</
tr
>\s*<
tr
>\s*<td colspan=
"3"
bgcolor=
"F4EBCC"
>\s*(.*?)<
tr
class=
'catdis'
>!s)
{
$story
= $1;
}
if
(
$story
)
{
$story
=
$self
->tidy_chars(
$story
);
}
else
{
die
"Failed to extract story for $title"
;
}
my
$story_title
=
"$title: $chapter"
;
$story_title
=
$title
if
(
$title
eq
$chapter
);
$story_title
=
$title
if
(
$chapter
eq
''
);
my
$out
=
''
;
if
(
$story
)
{
$out
.=
"<h1>$story_title</h1>\n"
;
$out
.=
"<p>by $author</p>\n"
;
$out
.=
"$story"
;
}
return
(
$out
,
$story_title
);
}
sub
parse_toc {
my
$self
=
shift
;
my
%args
= (
url
=>
''
,
content
=>
''
,
@_
);
my
%info
= ();
my
$content
=
$args
{content};
my
@chapters
= ();
$info
{url} =
$args
{url};
my
$sid
=
''
;
if
(
$args
{url} =~ m
{
$sid
= $1;
}
else
{
return
$self
->SUPER::parse_toc(
%args
);
}
$info
{title} =
$self
->parse_title(
%args
);
$info
{author} =
$self
->parse_author(
%args
);
$info
{summary} =
$self
->parse_summary(
%args
);
$info
{characters} =
$self
->parse_characters(
%args
);
$info
{category} =
$self
->parse_category(
%args
);
$info
{universe} =
'Harry Potter'
;
$info
{rating} =
'Adult'
;
my
$auth_id
=
''
;
if
(
$content
=~ m/Author:\s*<a href=
'authors\.php\?no=(\d+)'
>/s)
{
$auth_id
= $1;
}
if
(
$auth_id
and
$sid
)
{
if
(
$auth_page
=~ m
{
$info
{summary} = $1;
}
}
if
(!
$info
{summary})
{
$info
{summary} =
$self
->SUPER::parse_summary(
%args
);
}
$info
{chapters} =
$self
->parse_chapter_urls(
%args
,
sid
=>
$sid
);
return
%info
;
}
sub
parse_chapter_urls {
my
$self
=
shift
;
my
%args
= (
url
=>
''
,
content
=>
''
,
@_
);
my
$content
=
$args
{content};
my
$sid
=
$args
{sid};
my
@chapters
= ();
if
(
defined
$args
{urls})
{
@chapters
= @{
$args
{urls}};
}
if
(
@chapters
== 1)
{
@chapters
= ();
my
$max_chapter
= 0;
while
(
$content
=~ m
{
my
$a_ch
= $1;
if
(
$a_ch
>
$max_chapter
)
{
$max_chapter
=
$a_ch
;
}
}
for
(
my
$ch
= 1;
$ch
<=
$max_chapter
;
$ch
++)
{
my
$ch_url
=
sprintf
(
$fmt
,
$sid
,
$ch
);
warn
"chapter=$ch_url\n"
if
(
$self
->{verbose} > 1);
push
@chapters
,
$ch_url
;
}
}
return
\
@chapters
;
}
sub
parse_title {
my
$self
=
shift
;
my
%args
= (
url
=>
''
,
content
=>
''
,
@_
);
my
$content
=
$args
{content};
my
$title
=
''
;
if
(
$content
=~ m
{
$title
= $1;
}
else
{
$title
=
$self
->SUPER::parse_title(
%args
);
}
$title
=~ s/\s+$//;
return
$title
;
}
sub
parse_author {
my
$self
=
shift
;
my
%args
= (
url
=>
''
,
content
=>
''
,
@_
);
my
$content
=
$args
{content};
my
$author
=
''
;
if
(
$content
=~ m/Author:\s*<a href=
'authors\.php\?no=\d+'
>\s*([^<]+)\s*<\/a>/s)
{
$author
= $1;
}
else
{
$author
=
$self
->SUPER::parse_author(
%args
);
}
return
$author
;
}
sub
parse_characters {
my
$self
=
shift
;
my
%args
= (
url
=>
''
,
content
=>
''
,
@_
);
my
$content
=
$args
{content};
my
$characters
=
''
;
if
(
$content
=~ m
{
$characters
= $1 .
', '
. $2;
$characters
=~ s/Arthur/Arthur Weasley/;
$characters
=~ s/Bill/Bill Weasley/;
$characters
=~ s/Charlie/Charlie Weasley/;
$characters
=~ s/Draco/Draco Malfoy/;
$characters
=~ s/Dudley/Dudley Dursley/;
$characters
=~ s/Fred/Fred Weasley/;
$characters
=~ s/George/George Weasley/;
$characters
=~ s/Ginny/Ginny Weasley/;
$characters
=~ s/Harry/Harry Potter/;
$characters
=~ s/Hermione/Hermione Granger/;
$characters
=~ s/James/James Potter/;
$characters
=~ s/Lavender/Lavender Brown/;
$characters
=~ s/Lavendar/Lavender Brown/;
$characters
=~ s/Lily/Lily Evans/;
$characters
=~ s/Lucius/Lucius Malfoy/;
$characters
=~ s/Luna/Luna Lovegood/;
$characters
=~ s/McGonagall/Minerva McGonagall/;
$characters
=~ s/Molly/Molly Weasley/;
$characters
=~ s/Narcissa/Narcissa Malfoy/;
$characters
=~ s/Neville/Neville Longbottom/;
$characters
=~ s/Remus/Remus Lupin/;
$characters
=~ s/Ron/Ron Weasley/;
$characters
=~ s/Snape/Severus Snape/;
}
else
{
$characters
=
$self
->SUPER::parse_characters(
%args
);
}
return
$characters
;
}
sub
parse_ch_title {
my
$self
=
shift
;
my
%args
= (
url
=>
''
,
content
=>
''
,
@_
);
my
$content
=
$args
{content};
my
$title
=
''
;
if
(
$content
=~ m
{
$title
= $1;
}
elsif
(
$content
=~ m
{
$title
= $1;
}
else
{
$title
=
$self
->parse_title(
%args
);
}
return
$title
;
}
1;