| 1 |
|
|---|
| 2 |
use Plagger::Util qw( decode_content ); |
|---|
| 3 |
|
|---|
| 4 |
sub handle { |
|---|
| 5 |
my ($self, $url) = @_; |
|---|
| 6 |
$url =~ qr!http://(?:www.)?ustream.tv/recorded/.+!; |
|---|
| 7 |
} |
|---|
| 8 |
|
|---|
| 9 |
sub find { |
|---|
| 10 |
my ($self, $args) = @_; |
|---|
| 11 |
my $url = $args->{url}; |
|---|
| 12 |
|
|---|
| 13 |
return unless my($cid) = $url =~ qr!http://(?:www.)?ustream.tv/recorded/(.+)!; |
|---|
| 14 |
my $request_body = _request_body($cid); |
|---|
| 15 |
|
|---|
| 16 |
my $req = HTTP::Request->new( POST => 'http://gw.ustream.tv/gateway.php' ); |
|---|
| 17 |
$req->content( $request_body ); |
|---|
| 18 |
$req->content_type('application/x-amf'); |
|---|
| 19 |
$req->content_length( length $request_body ); |
|---|
| 20 |
|
|---|
| 21 |
my $ua = Plagger::UserAgent->new; |
|---|
| 22 |
my $res = $ua->request($req); |
|---|
| 23 |
my $response_body = $res->content; |
|---|
| 24 |
|
|---|
| 25 |
my $null = pack('C', 0); |
|---|
| 26 |
return unless my($server_id) = $response_body =~ /server_id...([^$null]+)/; |
|---|
| 27 |
return unless my($video_name) = $response_body =~ /video_name...([^$null]+)/; |
|---|
| 28 |
|
|---|
| 29 |
my $enclosure = Plagger::Enclosure->new; |
|---|
| 30 |
$enclosure->url("http://flash$server_id.ustream.tv:18881/$video_name.flv"); |
|---|
| 31 |
$enclosure->type('video/flv'); |
|---|
| 32 |
$video_name =~ s!/!_!g; |
|---|
| 33 |
$enclosure->filename("$video_name.flv"); |
|---|
| 34 |
return $enclosure; |
|---|
| 35 |
|
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
sub _request_body { |
|---|
| 39 |
my $cid = shift; |
|---|
| 40 |
|
|---|
| 41 |
my $body = pack('C*', qw( 0 0 0 0 0 1 0 )); |
|---|
| 42 |
$body .= pack('C', 0x12) . 'client.watch_video'; |
|---|
| 43 |
$body .= pack('C*', qw( 0 2 47 49 0 0 0 49 10 0 0 0 1 3 0 )); |
|---|
| 44 |
$body .= pack('C', 3) . 'cid' . pack('C*', 2, 0, length($cid)) . $cid; |
|---|
| 45 |
$body .= pack('C*', qw( 0 0 9 )); |
|---|
| 46 |
|
|---|
| 47 |
$body; |
|---|
| 48 |
} |
|---|