Changeset 3809

Show
Ignore:
Timestamp:
12/30/07 17:26:52 (5 years ago)
Author:
yusukebe
Message:

this versionup enables create object from id

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/WWW-YourFileHost/trunk/lib/WWW/YourFileHost.pm

    r3614 r3809  
    1010use CGI; 
    1111 
    12 our $VERSION = '0.01'; 
     12our $VERSION = '0.02'; 
    1313 
    1414sub new { 
    1515    my ( $class, %opt ) = @_; 
    1616    my $self = bless { %opt }, $class; 
    17     $self->_scrape; 
     17    if ($self->{url}){ 
     18        $self->_scrape; 
     19        $self->_get_info; 
     20    } 
     21    $self->_get_info if $self->{id}; 
     22    croak "url or id param is requred" unless $self->{_query}; 
    1823    $self; 
    1924} 
     
    2126sub _scrape { 
    2227    my $self = shift; 
    23     my $url = $self->{url} || croak "url param is requred"; 
     28    my $url = $self->{url}; 
    2429    croak "url is not yourfilehost link" 
    2530        unless $url =~ m!yourfilehost.com/media.php\?!; 
     
    3338    croak "video information is not found" unless $res->{value}; 
    3439    $res->{value} =~ m/&video=(.*?)&/; 
    35     my $api_url = uri_unescape($1); 
    36      
     40    $self->{api_url} = uri_unescape($1); 
     41} 
     42sub _get_info { 
     43    my $self = shift; 
     44    my $api_url = $self->{api_url} || 
     45        "http://www.yourfilehost.com/video-embed.php?vidlink=&cid=" . $self->{id}; 
    3746    my $ua = LWP::UserAgent->new(); 
    38     $res = $ua->get($api_url); 
     47    my $res = $ua->get($api_url); 
    3948    croak "" unless $res->is_success; 
    4049    my $query = CGI->new($res->content); 
    41     $self->{query} = $query; 
     50    $self->{_query} = $query; 
    4251} 
    4352 
    4453sub photo { 
    4554    my $self = shift; 
    46     return $self->{query}->param("photo"); 
     55    return $self->{_query}->param("photo"); 
    4756} 
    4857 
    4958sub video_id { 
    5059    my $self = shift; 
    51     return $self->{query}->param("video_id"); 
     60    return $self->{_query}->param("video_id"); 
    5261} 
    5362 
    5463sub embed { 
    5564    my $self = shift; 
    56     return $self->{query}->param("embed"); 
     65    return $self->{_query}->param("embed"); 
     66} 
     67 
     68sub id { 
     69    my $self = shift; 
     70    my $id = $1 if $self->{_query}->param("photo") =~ m!.*/(.*?).jpg!; 
     71    return $id; 
    5772} 
    5873 
     
    6782=head1 VERSION 
    6883 
    69 This document describes WWW::YourFileHost version 0.0.1 
     84This document describes WWW::YourFileHost version 0.0.2 
    7085 
    7186=head1 SYNOPSIS 
     
    7489 
    7590    my $url =  
    76     "http://www.yourfilehost.com/media.php?cat=video&file=hoge.wmv"; 
     91      "http://www.yourfilehost.com/media.php?cat=video&file=hoge.wmv"; 
    7792    my $yourfilehost = WWW::YourFileHost->new( url => $url ); 
     93    # or my $yourfilehost = WWW::YourFileHost->new( id => $id ); 
    7894    print $yourfilehost->photo . "\n"; 
    7995    print $yourfilehost->video_id . "\n"; 
    8096    print $yourfilehost->embed . "\n"; 
     97 
    8198 
    8299=head1 AUTHOR