| 1 | package WWW::Asg; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Digest::MD5 qw(md5_hex); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use HTML::TreeBuilder::XPath; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use DateTime::Format::ISO8601; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use DateTime::Format::Strptime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | #use Smart::Comments; | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | WWW::Asg - Get video informations from Asg.to | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 VERSION | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Version 0.05 | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 3 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | use WWW::Asg; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | my $asg = WWW::Asg->new(); | ||||||||||||||||||||||||||||
| 34 | my @videos = $asg->latest_videos($page); | ||||||||||||||||||||||||||||
| 35 | foreach my $v ( @videos ) { | ||||||||||||||||||||||||||||
| 36 | print $asg->{embed} . "\n"; | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 3 | my $strp = DateTime::Format::Strptime->new( | |||||||||||||||||||||||||||
| 42 | pattern => '%Y.%m.%d %H:%M', | ||||||||||||||||||||||||||||
| 43 | locale => 'ja_JP', | ||||||||||||||||||||||||||||
| 44 | time_zone => 'Asia/Tokyo', | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | 3 | my %default_condition = ( | |||||||||||||||||||||||||||
| 47 | q => '', | ||||||||||||||||||||||||||||
| 48 | searchVideo => 'true', | ||||||||||||||||||||||||||||
| 49 | minimumLength => '', | ||||||||||||||||||||||||||||
| 50 | searchCategory => 'any', | ||||||||||||||||||||||||||||
| 51 | sort => 'date', | ||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||
| 53 | 3 | my $embed_code_format = | |||||||||||||||||||||||||||
| 54 | '<script type="text/javascript" src="http://asg.to/js/past_uraui.js"></script><script type="text/javascript">Purauifla("mcd=%s", 450, 372);</script>'; | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head2 new | ||||||||||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 3 | my ( $class, %opt ) = @_; | |||||||||||||||||||||||||||
| 63 | 3 | my $self = bless {%opt}, $class; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 3 | ▶ | $self->{ua} = LWP::UserAgent->new unless $self->{ua}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 3 | $self; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head2 search(%condition) | ||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub search { | ||||||||||||||||||||||||||
|
Subroutine
search: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 0 | my ( $self, %condition ) = @_; | |||||||||||||||||||||||||||
| 75 | 0 | %condition = ( %default_condition, %condition ); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my $uri = URI->new('http://asg.to/search'); | |||||||||||||||||||||||||||
| 78 | 0 | $uri->query_form( \%condition ); | |||||||||||||||||||||||||||
| 79 | 0 | my $res = $self->{ua}->get( $uri->as_string ); | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | return () unless $res->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | $self->_extract_videos( $res->decoded_content ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head2 latest_videos($page) | ||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub latest_videos { | ||||||||||||||||||||||||||
|
Subroutine
latest_videos: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 0 | my ( $self, $page ) = @_; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | $page ||= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$page ||= 1
MC/DC0%0/1
$page ||= 1
$page
Truth table0%0/2
A
A= $page
| |||||||||||||||||||||||||||||
| 91 | 0 | my $res = $self->{ua}->get("http://asg.to/new-movie?page=$page"); | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | return () unless $res->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | $self->_extract_videos( $res->decoded_content ); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 2 | ▶ | sub _extract_videos { | ||||||||||||||||||||||||||
|
Subroutine
_extract_videos: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 98 | 2 | my ( $self, $html ) = @_; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | my $tree = HTML::TreeBuilder::XPath->new; | |||||||||||||||||||||||||||
| 101 | 2 | $tree->parse($html); | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | my $video_nodes = $tree->findnodes('//div[@id="list"]/div'); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | my @videos = (); | |||||||||||||||||||||||||||
| 106 | 2 | foreach my $node (@$video_nodes) { | |||||||||||||||||||||||||||
| 107 | 22 | my $video = $self->_extract_video($node); | |||||||||||||||||||||||||||
| 108 | 22 | ▶ | next if not $video or not %$video; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$video and %$video
MC/DC50%1/2
$video and %$video
$video
%$video
Truth table66%2/3
A and B
A= $videoB= %$video
| |||||||||||||||||||||||||||||
| 109 | 20 | push @videos, $video; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 2 | @videos; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 22 | ▶ | sub _extract_video { | ||||||||||||||||||||||||||
|
Subroutine
_extract_video: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 116 | 22 | my ( $self, $node ) = @_; | |||||||||||||||||||||||||||
| 117 | 22 | my $video = {}; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 22 | my $link_node = $node->findnodes('h3/a')->[0]; | |||||||||||||||||||||||||||
| 120 | 22 | ▶ | return undef unless $link_node; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # url | ||||||||||||||||||||||||||||
| 123 | 20 | my $url = $link_node->findvalue('@href'); | |||||||||||||||||||||||||||
| 124 | return undef | ||||||||||||||||||||||||||||
| 125 | 20 | ▶ | unless $url =~ /(http:\/\/asg\.to)?\/contentsPage\.html\?mcd=([^?&]+)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 20 | $video->{url} = "http://asg.to$url"; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # mcd | ||||||||||||||||||||||||||||
| 129 | 20 | $video->{mcd} = $2; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | # title | ||||||||||||||||||||||||||||
| 132 | 20 | my $title = $link_node->findvalue('@title'); | |||||||||||||||||||||||||||
| 133 | 20 | ▶ | $title = $1 if $title =~ /.+アダルト動画:(.+)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 20 | $video->{title} = $self->_trim($title); | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 20 | my $list_info_nodes = $node->findnodes('div[@class="list-info"]/p'); | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # description | ||||||||||||||||||||||||||||
| 139 | 20 | my $description = $list_info_nodes->[3]->findvalue('.'); | |||||||||||||||||||||||||||
| 140 | 20 | ▶ | $description = $1 if $description =~ /.*紹介文:\s*(.+)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 20 | $video->{description} = $self->_trim($description); | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | # thumbnail | ||||||||||||||||||||||||||||
| 144 | 20 | $video->{thumbnail} = $node->findvalue('a/img[@class="shift-left"]/@src'); | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # date | ||||||||||||||||||||||||||||
| 147 | 20 | my $date = $list_info_nodes->[0]->findvalue('.'); | |||||||||||||||||||||||||||
| 148 | 20 | $video->{date} = $self->_date($date); | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | # ccd | ||||||||||||||||||||||||||||
| 151 | 20 | my $ccd_node = $list_info_nodes->[1]->findnodes('a')->[0]; | |||||||||||||||||||||||||||
| 152 | 20 | my $ccd = $ccd_node->findvalue('@href'); | |||||||||||||||||||||||||||
| 153 | 20 | ▶ | if ( $ccd =~ /(http:\/\/asg\.to)?\/categoryPage\.html\?ccd=([^?&]+)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | 20 | $video->{ccd} = $2; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | 20 | $video->{ccd_text} = $self->_trim( $ccd_node->findvalue('.') ); | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # play time | ||||||||||||||||||||||||||||
| 159 | 20 | my $play_time = $list_info_nodes->[2]->findvalue('.'); | |||||||||||||||||||||||||||
| 160 | 20 | ▶ | if ( $play_time =~ /.*\s([0-9]{1,3}:[0-9]{1,2}).*/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 19 | my $play_time_text = $1; | |||||||||||||||||||||||||||
| 162 | 19 | my @splited = split ':', $play_time_text; | |||||||||||||||||||||||||||
| 163 | 19 | my $play_time_sec = int( $splited[0] ) * 60 + int( $splited[1] ); | |||||||||||||||||||||||||||
| 164 | 19 | $video->{play_time} = $play_time_sec; | |||||||||||||||||||||||||||
| 165 | 19 | $video->{play_time_text} = $self->_trim($play_time_text); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | # embed code | ||||||||||||||||||||||||||||
| 169 | 20 | $video->{embed} = sprintf( $embed_code_format, $video->{mcd} ); | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | ### $video | ||||||||||||||||||||||||||||
| 172 | 20 | return $video; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 26 | ▶ | sub _date { | ||||||||||||||||||||||||||
|
Subroutine
_date: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 176 | 26 | my ( $self, $date_str ) = @_; | |||||||||||||||||||||||||||
| 177 | 26 | $self->_trim($date_str); | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 26 | my $dt = undef; | |||||||||||||||||||||||||||
| 180 | 26 | ▶ | if ( $date_str =~ /.*([0-9]{2,4}\.[0-9]{2}\.[0-9]{2} [0-9]{2}:[0-9]{2}).*/ ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 181 | { | ||||||||||||||||||||||||||||
| 182 | 22 | my $date = "20" . $1; | |||||||||||||||||||||||||||
| 183 | 22 | $dt = $strp->parse_datetime($date); | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | elsif ( $date_str =~ | ||||||||||||||||||||||||||||
| 186 | /.*([0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}:[0-9]{2}(:[0-9]{2}Z)?).*/ ) | ||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||
| 188 | 4 | my $date = $1; | |||||||||||||||||||||||||||
| 189 | 4 | $dt = DateTime::Format::ISO8601->new->parse_datetime($date); | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | else { | ||||||||||||||||||||||||||||
| 192 | 0 | return undef; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 26 | return $dt->iso8601; | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 105 | ▶ | sub _trim { | ||||||||||||||||||||||||||
|
Subroutine
_trim: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 199 | 105 | my ( $self, $str ) = @_; | |||||||||||||||||||||||||||
| 200 | 105 | ▶ | $str =~ s/^[\s ]*(.*?)[\s ]*$/$1/ if $str; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 105 | return $str; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | Tatsuya Fukata C<< <tatsuya.fukata@gmail.com> >> | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =head1 BUGS | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | Please report any bugs or feature requests to C<bug-www-asg at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 211 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Asg>. I will be notified, and then you'll | ||||||||||||||||||||||||||||
| 212 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | perldoc WWW::Asg | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | You can also look for information at: | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | =over 4 | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Asg> | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | L<http://annocpan.org/dist/WWW-Asg> | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | L<http://cpanratings.perl.org/d/WWW-Asg> | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | L<http://search.cpan.org/dist/WWW-Asg/> | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | =back | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | Copyright 2012 Tatsuya FUKATA. | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 247 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||
| 248 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | =cut | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 3 | 1; # End of WWW::Asg | |||||||||||||||||||||||||||