Changeset 3809
- Timestamp:
- 12/30/07 17:26:52 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/WWW-YourFileHost/trunk/lib/WWW/YourFileHost.pm
r3614 r3809 10 10 use CGI; 11 11 12 our $VERSION = '0.0 1';12 our $VERSION = '0.02'; 13 13 14 14 sub new { 15 15 my ( $class, %opt ) = @_; 16 16 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}; 18 23 $self; 19 24 } … … 21 26 sub _scrape { 22 27 my $self = shift; 23 my $url = $self->{url} || croak "url param is requred";28 my $url = $self->{url}; 24 29 croak "url is not yourfilehost link" 25 30 unless $url =~ m!yourfilehost.com/media.php\?!; … … 33 38 croak "video information is not found" unless $res->{value}; 34 39 $res->{value} =~ m/&video=(.*?)&/; 35 my $api_url = uri_unescape($1); 36 40 $self->{api_url} = uri_unescape($1); 41 } 42 sub _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}; 37 46 my $ua = LWP::UserAgent->new(); 38 $res = $ua->get($api_url);47 my $res = $ua->get($api_url); 39 48 croak "" unless $res->is_success; 40 49 my $query = CGI->new($res->content); 41 $self->{ query} = $query;50 $self->{_query} = $query; 42 51 } 43 52 44 53 sub photo { 45 54 my $self = shift; 46 return $self->{ query}->param("photo");55 return $self->{_query}->param("photo"); 47 56 } 48 57 49 58 sub video_id { 50 59 my $self = shift; 51 return $self->{ query}->param("video_id");60 return $self->{_query}->param("video_id"); 52 61 } 53 62 54 63 sub embed { 55 64 my $self = shift; 56 return $self->{query}->param("embed"); 65 return $self->{_query}->param("embed"); 66 } 67 68 sub id { 69 my $self = shift; 70 my $id = $1 if $self->{_query}->param("photo") =~ m!.*/(.*?).jpg!; 71 return $id; 57 72 } 58 73 … … 67 82 =head1 VERSION 68 83 69 This document describes WWW::YourFileHost version 0.0. 184 This document describes WWW::YourFileHost version 0.0.2 70 85 71 86 =head1 SYNOPSIS … … 74 89 75 90 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"; 77 92 my $yourfilehost = WWW::YourFileHost->new( url => $url ); 93 # or my $yourfilehost = WWW::YourFileHost->new( id => $id ); 78 94 print $yourfilehost->photo . "\n"; 79 95 print $yourfilehost->video_id . "\n"; 80 96 print $yourfilehost->embed . "\n"; 97 81 98 82 99 =head1 AUTHOR
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)