aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZakFlash <zakflashvideo@gmail.com>2012-07-21 22:19:24 +0100
committerZakFlash <zakflashvideo@gmail.com>2012-07-21 22:19:24 +0100
commit1423e34540e506a3d468a088f68d05da7bba29fd (patch)
treedddc9091f2ee2726e570c223d33b53d7c132fb92
parentd630a98d8a5b1b2186d1a5a42bf24291aa232487 (diff)
downloadget-flash-videos-1423e34540e506a3d468a088f68d05da7bba29fd.tar.gz
Default to highest quality Brightcove stream
Fixes issue 401
-rw-r--r--lib/FlashVideo/Site/Brightcove.pm23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/FlashVideo/Site/Brightcove.pm b/lib/FlashVideo/Site/Brightcove.pm
index c32db02..6080491 100644
--- a/lib/FlashVideo/Site/Brightcove.pm
+++ b/lib/FlashVideo/Site/Brightcove.pm
@@ -125,10 +125,23 @@ EOF
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];
+ # There might be different versions (aka "renditions") of this video -
+ # if so, choose the highest quality.
+ #
+ # TODO: support quality settings
+ my $rtmp_url = $d->{FLVFullLengthURL};
+
+ if ($d->{renditions} and ref($d->{renditions}) eq 'ARRAY') {
+ my @renditions = sort { $a->{encodingRate} <=> $b->{encodingRate} }
+ @{ $d->{renditions} };
+
+ $rtmp_url = $renditions[-1]->{defaultURL};
+ }
+
+ my $host = ($rtmp_url =~ m!rtmp://(.*?)/!)[0];
+ my $file = ($rtmp_url =~ m!&([a-z0-9:]+/.*?)(?:&|$)!)[0];
+ my $app = ($rtmp_url =~ m!//.*?/(.*?)/&!)[0];
+ my $filename = ($rtmp_url =~ m!&.*?/([^/&]+)(?:&|$)!)[0];
$app .= "?videoId=$d->{id}&lineUpId=$d->{lineupId}&pubId=$d->{publisherId}&playerId=$player_id&playerTag=&affiliateId=";
@@ -137,7 +150,7 @@ EOF
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],
+ auth => ($rtmp_url =~ /^[^&]+&(.*)$/)[0],
rtmp => "rtmp://$host/$app",
playpath => $file,
flv => "$filename.flv",