Changeset 28301 for lang/perl/WWW-Tube8

Show
Ignore:
Timestamp:
01/12/09 00:15:27 (13 months ago)
Author:
bayashi
Message:

get more info. and add tests.

Location:
lang/perl/WWW-Tube8/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/WWW-Tube8/trunk/Build.PL

    r28249 r28301  
    99    dist_version_from   => 'lib/WWW/Tube8.pm', 
    1010    requires => { 
    11         'Test::More'     => 0, 
    12         'Carp'           => 0, 
    13         'LWP::UserAgent' => 0, 
     11        'Test::More'      => 0, 
     12        'Carp'            => 0, 
     13        'LWP::UserAgent'  => 0, 
     14        'Class::Accessor' => 0, 
    1415    }, 
    1516    add_to_cleanup      => [ 'WWW-Tube8-*' ], 
  • lang/perl/WWW-Tube8/trunk/Changes

    r28249 r28301  
    11Revision history for WWW-Tube8 
     2 
     30.0.2  Mon Jan 12 00:05:05 2009 
     4       get more info. and add tests. 
    25 
    360.0.1  Sat Jan 10 12:34:56 2009 
  • lang/perl/WWW-Tube8/trunk/META.yml

    r28249 r28301  
    11--- 
    22name: WWW-Tube8 
    3 version: 0.0.1 
     3version: 0.0.2 
    44author: 
    55  - 'Dai Okabayashi <bayashi@cpan.org>' 
     
    1010requires: 
    1111  Carp: 0 
     12  Class::Accessor: 0 
    1213  LWP::UserAgent: 0 
    1314  Test::More: 0 
     
    1516  WWW::Tube8: 
    1617    file: lib/WWW/Tube8.pm 
    17     version: 0.0.1 
     18    version: 0.0.2 
    1819generated_by: Module::Build version 0.3 
    1920meta-spec: 
  • lang/perl/WWW-Tube8/trunk/lib/WWW/Tube8.pm

    r28249 r28301  
    55use Carp qw( croak ); 
    66 
    7 use version; our $VERSION = qv('0.0.1'); 
     7use version; our $VERSION = qv('0.0.2'); 
    88 
    99use LWP::UserAgent; 
     10 
     11use base qw(Class::Accessor); 
     12__PACKAGE__->mk_accessors( 
     13    qw( flv thumb get_3gp url id title title_inurl category category_url duration ) 
     14); 
    1015 
    1116sub new { 
     
    1924 
    2025    croak "url is required" unless $self->{url}; 
    21     croak "url is not tube8" if $self->{url} !~ /^http:\/\/www\.tube8\.com\//; 
    22  
     26    croak "url is wrong (perhaps not movie page of tube8.com)" 
     27        if $self->url !~ m!^http://www.tube8.com/[^/]+/([^/]+)/(\d+)/!; 
     28    $self->title_inurl($1); 
     29    $self->id($2); 
    2330    $self->_get_info; 
    2431 
     
    3441 
    3542    while ( $tube8_page =~ s/so\.addVariable\('([^']+)','([^']+)'\);// ) { 
    36         my $key   = $1; 
    37         my $value = $2; 
     43        my ($key, $value) = ($1, $2); 
    3844        if ($key) { 
    3945            if ( $key eq 'videoUrl' && $value =~ /\.flv$/ ) { 
    40                 $self->{flv} = $value; 
     46                $self->flv($value); 
    4147            } 
    4248            elsif ( $key eq 'imageUrl' && $value =~ /\.jpg$/ ) { 
    43                 $self->{thumb} = 'http://www.tube8.com' . $value; 
     49                $self->thumb('http://www.tube8.com' . $value); 
    4450            } 
    4551        } 
    4652    } 
    47     ( $self->{'3gp'} ) 
    48         = ( 
    49         $tube8_page =~ /<a href="([^"]+\.3gp)">Download video for mobile/ ); 
    50 } 
    51  
    52 sub flv { 
    53     my $self = shift; 
    54  
    55     return $self->{flv} if $self->{flv}; 
    56 } 
    57  
    58 sub thumb { 
    59     my $self = shift; 
    60  
    61     return $self->{thumb} if $self->{thumb}; 
    62 } 
    63  
    64 sub get_3gp { 
    65     my $self = shift; 
    66  
    67     return $self->{'3gp'} if $self->{'3gp'}; 
     53    $self->get_3gp( 
     54        $tube8_page =~ /<a href="([^"]+\.3gp)">Download video for mobile/ ) ; 
     55    $self->title( 
     56        $tube8_page =~ /<td[^>]+><strong>Title<\/strong>: ([^<]+)<\/td>/ ); 
     57    $self->duration( 
     58        $tube8_page =~ /<td[^>]+><strong>Duration<\/strong>: ([^<]+)<\/td>/ ); 
     59    $tube8_page =~ /<td[^>]+><strong>Category<\/strong>: <a href='([^']+)'><b>([^<]+)<\/b><\/a><\/td>/; 
     60    $self->category_url($1); 
     61    $self->category($2); 
    6862} 
    6963 
     
    8983    my $t8 = WWW::Tube8->new({ 
    9084        url => 'http://www.tube8.com/category/hoge-hoge-/00000/', 
    91         ua  => $ua, 
     85        ua  => $ua, # optional 
    9286    }); 
    9387 
    94     print $t8->flv     . "\n"; 
    95     print $t8->thumb   . "\n"; 
    96     print $t8->get_3gp . "\n"; 
     88    print $t8->flv          . "\n"; 
     89    print $t8->thumb        . "\n"; 
     90    print $t8->get_3gp      . "\n"; 
     91    print $t8->url          . "\n"; 
     92    print $t8->id           . "\n"; 
     93    print $t8->title        . "\n"; 
     94    print $t8->title_inurl  . "\n"; 
     95    print $t8->category     . "\n"; 
     96    print $t8->category_url . "\n"; 
     97    print $t8->duration     . "\n"; 
    9798 
    9899 
     
    104105 
    105106Creates a new WWW::Tube8 instance. 
     107required param only url. 
     108 
     109 
     110you can get video infomations like follow 
    106111 
    107112=item flv 
    108113 
    109 get the url of flv file 
    110  
    111114=item thumb 
    112  
    113 get the url of thumbnail file 
    114115 
    115116=item get_3gp 
    116117 
    117 get the url of 3gp(mp4) file 
     118=item url 
     119 
     120=item id 
     121 
     122=item title 
     123 
     124=item title_inurl 
     125 
     126=item category 
     127 
     128=item category_url 
     129 
     130=item duration 
    118131 
    119132=back 
  • lang/perl/WWW-Tube8/trunk/t/01.basic.t

    r28249 r28301  
    11use strict; 
    2 use Test::More tests => 8; 
     2use Test::More tests => 14; 
    33use WWW::Tube8; 
    44 
     
    1616    my $t8 = WWW::Tube8->new({ url => 'http://www.example.com/' }); 
    1717}; 
    18 like $@, qr/url is not tube8/, 'new : not tube8 url'; 
     18like $@, qr/url is wrong/, 'new : not tube8 url'; 
    1919 
    2020my $ua = LWP::UserAgent->new(agent => 'WWW::Tube8.test'); 
     
    3636     'get_3gp : get url of 3gp file'; 
    3737 
     38is $t8->id, '71930', 'id : get id of video'; 
    3839 
     40is $t8->title, 'Japanese AV Haruka Sanada', 'title : get title of video'; 
    3941 
     42is $t8->title_inurl, 'japanese-av-haruka-sanada', 'title_inurl : get title of video for url'; 
     43 
     44is $t8->category, 'Asian', 'category : get category of video'; 
     45 
     46is $t8->category_url, 'http://www.tube8.com/cat/asian/12/', 'category_url : get category link of video'; 
     47 
     48is $t8->duration, '23:00', 'duration : get duration of video';