App-get_flash_videos
view release on metacpan or search on metacpan
lib/FlashVideo/Site/Brightcove.pm view on Meta::CPAN
my $data = $packet->serialize;
$browser->post(
"http://c.brightcove.com/services/amfgateway",
Content_Type => "application/x-amf",
Content => $data
);
die "Failed to post to Brightcove AMF gateway"
unless $browser->response->is_success;
$packet = Data::AMF::Packet->deserialize($browser->content);
if($self->debug) {
require Data::Dumper;
debug Data::Dumper::Dumper($packet);
}
if(ref $packet->messages->[0]->{value} ne 'ARRAY') {
die "Unexpected data from AMF gateway";
}
my @found;
for (@{$packet->messages->[0]->{value}}) {
if ($_->{data}->{videoDTO}) {
push @found, $_->{data}->{videoDTO};
}
if ($_->{data}->{videoDTOs}) {
push @found, @{$_->{data}->{videoDTOs}};
}
}
my @rtmpdump_commands;
for my $d (@found) {
next if $metadata->{videoId} && $d->{id} != $metadata->{videoId};
my $host = ($d->{FLVFullLengthURL} =~ m!rtmp://(.*?)/!)[0];
my $file = ($d->{FLVFullLengthURL} =~ m!&([a-z0-9:]+/.*?)(?:&|$)!)[0];
my $app = ($d->{FLVFullLengthURL} =~ m!//.*?/(.*?)/&!)[0];
my $filename = ($d->{FLVFullLengthURL} =~ m!&.*?/([^/&]+)(?:&|$)!)[0];
$app .= "?videoId=$d->{id}&lineUpId=$d->{lineupId}&pubId=$d->{publisherId}&playerId=$player_id&playerTag=&affiliateId=";
my $args = {
app => $app,
pageUrl => $page_url,
swfUrl => "http://admin.brightcove.com/viewer/federated/f_012.swf?bn=590&pubId=$d->{publisherId}",
tcUrl => "rtmp://$host:1935/$app",
auth => ($d->{FLVFullLengthURL} =~ /^[^&]+&(.*)$/)[0],
rtmp => "rtmp://$host/$app",
playpath => $file,
flv => "$filename.flv",
};
# Use sane filename
if ($d->{publisherName} and $d->{displayName}) {
$args->{flv} = title_to_filename("$d->{publisherName} - $d->{displayName}");
}
# In some cases, Brightcove doesn't use RTMP streaming - the file is
# downloaded via HTTP.
if (!$d->{FLVFullLengthStreamed}) {
info "Brightcove HTTP download detected";
return ($d->{FLVFullLengthURL}, $args->{flv});
}
push @rtmpdump_commands, $args;
}
if (@rtmpdump_commands > 1) {
return \@rtmpdump_commands;
}
else {
return $rtmpdump_commands[-1];
}
}
sub can_handle {
my($self, $browser, $url) = @_;
return 1 if $url && URI->new($url)->host =~ /\.brightcove\.com$/;
return $browser->content =~ /(playerI[dD]|brightcove.player.create)/
&& $browser->content =~ /brightcove/i;
}
1;
( run in 0.489 second using v1.01-cache-2.11-cpan-ceb78f64989 )