| 1 | package WWW::FetchStory::Fetcher::SSHGExchange; | ||||||||||
| 2 | 1 | $WWW::FetchStory::Fetcher::SSHGExchange::VERSION = '0.2602'; | |||||||||
| 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::SSHGExchange - fetching module for WWW::FetchStory | ||||||||||
| 8 | |||||||||||
| 9 | =head1 VERSION | ||||||||||
| 10 | |||||||||||
| 11 | version 0.2602 | ||||||||||
| 12 | |||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||
| 14 | |||||||||||
| 15 | This is the SSHGExchange story-fetching plugin for WWW::FetchStory. | ||||||||||
| 16 | |||||||||||
| 17 | =cut | ||||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | use parent qw(WWW::FetchStory::Fetcher::LiveJournal); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | =head1 METHODS | ||||||||||
| 22 | |||||||||||
| 23 | =head2 info | ||||||||||
| 24 | |||||||||||
| 25 | Information about the fetcher. | ||||||||||
| 26 | |||||||||||
| 27 | $info = $self->info(); | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | sub info { | ||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 32 | 0 | my $self = shift; | |||||||||
| 33 | |||||||||||
| 34 | 0 | my $info = "(http://community.livejournal.com/sshg_exchange/) 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 | 0 | ▶ | sub priority { | ||||||||
|
Subroutine
priority: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 58 | 0 | 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 | 0 | ▶ | sub allow { | ||||||||
|
Subroutine
allow: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 77 | 0 | my $self = shift; | |||||||||
| 78 | 0 | my $url = shift; | |||||||||
| 79 | |||||||||||
| 80 | 0 | return ($url =~ /(community\.livejournal\.com\/sshg[-_]exchange|sshg[-_]exchange\.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 | 0 | ▶ | sub parse_toc { | ||||||||
|
Subroutine
parse_toc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 114 | 0 | 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_exchange:\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 | $author =~ s/Temporarily Disillusioned/Unknown/; | |||||||||
| 137 | 0 | $info{author} = $author; | |||||||||
| 138 | |||||||||||
| 139 | 0 | $info{characters} = "Hermione Granger, Severus Snape"; | |||||||||
| 140 | 0 | $info{universe} = 'Harry Potter'; | |||||||||
| 141 | 0 | $info{recipient} = $self->parse_recipient(%args); | |||||||||
| 142 | 0 | $info{chapters} = $self->parse_chapter_urls(%args); | |||||||||
| 143 | |||||||||||
| 144 | 0 | return %info; | |||||||||
| 145 | } # parse_toc | ||||||||||
| 146 | |||||||||||
| 147 | =head2 parse_chapter_urls | ||||||||||
| 148 | |||||||||||
| 149 | Figure out the URLs for the chapters of this story. | ||||||||||
| 150 | |||||||||||
| 151 | =cut | ||||||||||
| 152 | 0 | ▶ | sub parse_chapter_urls { | ||||||||
|
Subroutine
parse_chapter_urls: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 153 | 0 | my $self = shift; | |||||||||
| 154 | 0 | my %args = ( | |||||||||
| 155 | url=>'', | ||||||||||
| 156 | content=>'', | ||||||||||
| 157 | @_ | ||||||||||
| 158 | ); | ||||||||||
| 159 | 0 | my $content = $args{content}; | |||||||||
| 160 | 0 | my $sid = $args{sid}; | |||||||||
| 161 | 0 | my @chapters = (); | |||||||||
| 162 | 0 | ▶ | if (defined $args{urls}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 163 | { | ||||||||||
| 164 | 0 | @chapters = @{$args{urls}}; | |||||||||
| 165 | 0 | ▶ | for (my $i = 0; $i < @chapters; $i++) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 166 | { | ||||||||||
| 167 | 0 | $chapters[$i] = sprintf('%s?format=light', $chapters[$i]); | |||||||||
| 168 | } | ||||||||||
| 169 | } | ||||||||||
| 170 | 0 | ▶ | if (@chapters == 1) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 171 | { | ||||||||||
| 172 | 0 | ▶ | while ($content =~ m/href=["'](http:\/\/sshg-(?:mod|gifts)\.livejournal\.com\/\d+.html)/sg) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 173 | { | ||||||||||
| 174 | 0 | my $ch_url = $1; | |||||||||
| 175 | 0 | ▶ | warn "chapter=$ch_url\n" if ($self->{verbose} > 1); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 176 | 0 | push @chapters, "${ch_url}?format=light"; | |||||||||
| 177 | } | ||||||||||
| 178 | } | ||||||||||
| 179 | |||||||||||
| 180 | 0 | return \@chapters; | |||||||||
| 181 | } # parse_chapter_urls | ||||||||||
| 182 | |||||||||||
| 183 | 1 | 1; # End of WWW::FetchStory::Fetcher::SSHGExchange | |||||||||
| 184 | __END__ | ||||||||||