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

get more info. and add tests.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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