| 1 | package WWW::YourFileHost; |
|---|
| 2 | |
|---|
| 3 | use warnings; |
|---|
| 4 | use strict; |
|---|
| 5 | use Carp; |
|---|
| 6 | use LWP::UserAgent; |
|---|
| 7 | use CGI; |
|---|
| 8 | |
|---|
| 9 | our $VERSION = '0.06'; |
|---|
| 10 | |
|---|
| 11 | sub new { |
|---|
| 12 | my ( $class, %opt ) = @_; |
|---|
| 13 | my $self = bless {%opt}, $class; |
|---|
| 14 | $self->{ua} = LWP::UserAgent->new unless $self->{ua}; |
|---|
| 15 | if ( $self->{url} ) { |
|---|
| 16 | $self->_scrape; |
|---|
| 17 | $self->_get_info; |
|---|
| 18 | } |
|---|
| 19 | $self->_get_info if $self->{id}; |
|---|
| 20 | croak "url or id param is requred" unless $self->{_query}; |
|---|
| 21 | $self; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | sub _scrape { |
|---|
| 25 | my $self = shift; |
|---|
| 26 | my $url = $self->{url}; |
|---|
| 27 | croak "url is not yourfilehost link" |
|---|
| 28 | unless $url =~ m!yourfilehost.com/media.php\?!; |
|---|
| 29 | my $res = $self->{ua}->get( $url ); |
|---|
| 30 | croak("LWP Error: " . $res->status_line ) if $res->is_error; |
|---|
| 31 | my ($cid) = $res->content =~ m!http://cdn.yourfilehost.com/unit1/flash\d/\w{2}/(\w+)\.flv\?!; |
|---|
| 32 | $self->{id} = $cid; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | sub _get_info { |
|---|
| 36 | my $self = shift; |
|---|
| 37 | my $api_url = $self->{api_url} |
|---|
| 38 | || "http://www.yourfilehost.com/video-embed-code-new.php?vidlink=&cid=" |
|---|
| 39 | . $self->{id}; |
|---|
| 40 | my $ua = $self->{ua}; #LWP::UserAgent->new(); |
|---|
| 41 | my $res = $ua->get($api_url); |
|---|
| 42 | croak "can't get yourfilehost page" unless $res->is_success; |
|---|
| 43 | my $query = CGI->new( $res->content ); |
|---|
| 44 | $self->{_query} = $query; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | sub photo { |
|---|
| 48 | my $self = shift; |
|---|
| 49 | return $self->{_query}->param("photo"); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | sub video_id { |
|---|
| 53 | my $self = shift; |
|---|
| 54 | return $self->{_query}->param("video_id"); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | sub embed { |
|---|
| 58 | my $self = shift; |
|---|
| 59 | return $self->{_query}->param("embed"); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | sub id { |
|---|
| 63 | my $self = shift; |
|---|
| 64 | my $id; |
|---|
| 65 | $id = $1 if $self->{_query}->param("photo") =~ m!.*/(.*?).jpg!; |
|---|
| 66 | return $id; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | sub swf { |
|---|
| 70 | my $self = shift; |
|---|
| 71 | return $self->{swf}; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | 1; |
|---|
| 75 | |
|---|
| 76 | __END__ |
|---|
| 77 | |
|---|
| 78 | =head1 NAME |
|---|
| 79 | |
|---|
| 80 | WWW::YourFileHost - Get video informations from YourFileHost |
|---|
| 81 | |
|---|
| 82 | =head1 SYNOPSIS |
|---|
| 83 | |
|---|
| 84 | use LWP::UserAgent; |
|---|
| 85 | use WWW::YourFileHost; |
|---|
| 86 | use Perl6::Say; |
|---|
| 87 | |
|---|
| 88 | my $url = "http://www.yourfilehost.com/media.php?cat=video&file=hoge.wmv"; |
|---|
| 89 | my $ua = LWP::UserAgent->new( agent => "WWW::YourFileHost" ); |
|---|
| 90 | $ua->cookie_jar( HTTP::Cookies->new ); |
|---|
| 91 | my $yourfilehost = WWW::YourFileHost->new( url => $url , ua => $ua ); |
|---|
| 92 | say $yourfilehost->photo; |
|---|
| 93 | say $yourfilehost->video_id; |
|---|
| 94 | say $yourfilehost->embed; |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | =head1 AUTHOR |
|---|
| 98 | |
|---|
| 99 | Yusuke Wada C<< <yusuke@kamawada.com> >> |
|---|
| 100 | |
|---|
| 101 | =head1 LICENCE AND COPYRIGHT |
|---|
| 102 | |
|---|
| 103 | This module is free software; you can redistribute it and/or |
|---|
| 104 | modify it under the same terms as Perl itself. See L<perlartistic>. |
|---|
| 105 | |
|---|
| 106 | =cut |
|---|