/usr/share/perl5/FlashVideo/Site/Tv3.pm is in get-flash-videos 1.25.98-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | # Part of get-flash-videos. See get_flash_videos for copyright.
package FlashVideo::Site::Tv3;
use strict;
use FlashVideo::Utils;
our $VERSION = '0.04';
sub Version() { $VERSION; }
sub getSloc($) {
return "tv3";
}
sub find_video {
my ($self, $browser, $embed_url, $prefs) = @_;
my $content = $browser->content;
#open(F, "> content.html");print F $content;close(F);
if ($content !~ m/var\s+video\s*=\s*\"[\/\*]([^"]+)\"\s*;/s) {
die "Unable to parse video path from web page";
}
my $replace = $1;
$replace =~ s/\*/\//sg;
if ($content !~ m/var\s+geo\s*=\s*\"([^"]+)\"\s*;/s) {
die "Unable to determine geo mode";
}
my $geo = $1;
debug "GEO mode: $geo";
my $sloc = $self->getSloc();;
# As per the JavaScript on the episode base page, for TV3's current
# affairs programs the requested source location should be altered
# to "3news" instead of "tv3".
if ($content =~ m/var\s+pageloc\s*=\s*\'([^']+)\'\s*;/s) {
my $pageloc = $1;
debug "pageloc : $pageloc";
if ($pageloc =~ m/^[^-]+-[^-]+-[^-]+-[^-]+-currentaffairs-/si) {
# if sect4 == "currentaffairs" then sloc="3news"
$sloc = "3news";
}
} else {
debug "No pageloc parsed, optimistically continuing...";
}
if ($content !~ m/src=['"](\/[A-Za-z0-9\/]+\/player[-\d]+\.min\.js\?(?:|v=[0-9A-Za-z]*))['"](\>|\+ord)/s) {
die "Unable to locate player module";
}
my $basePlayer = $1;
my $withOrd = $2 =~ m/ord/s;
my $ord = "";
if ($withOrd) {
# The player has, historically, always has a random component
# appended to a fixed numeric prefix that will normally be 16
# decimal digits long.
for (my $c = 0; $c < 16; $c++) {
$ord .= int(rand(10));
}
# Strip all leading zeros, but make sure there's at least one
# (possibly zero) digit left.
$ord =~ s/^0+(.)/$1/gs;
}
my $player = $basePlayer . $ord;
# Default title is perfect. We need to do this before we re-use the
# browser to obtain other files.
my $filename = title_to_filename(extract_title($browser));
$filename ||= get_video_filename();
debug "Trying to get player: $player";
#
# Getting the player.js isn't strictly necessary, but it allows us
# to check assumptions, and not have to hard code the token - which
# potentially might be changed from time to time.
#
my $smilPath = "/portals/0/video/smil1500-2.aspx";
my $secureToken;
{
my $playerResponse = $browser->get($player);
die "Failed to get player.js" if !$playerResponse->is_success();
my $playerContent = $playerResponse->decoded_content();
if ($playerContent !~ m/securetoken\s*:\s*\"([^\"]+)\"/s) {
die "Unable to obtain securetoken";
}
$secureToken = $1;
debug "Securetoken = $secureToken";
my $smilPathRE = quotemeta($smilPath);
if ($playerContent !~ m/$smilPathRE/s) {
die "The expected SMIL path is not present";
}
}
#
# Default is "non-geo", and we've seen at least two values for the
# "geo" variable, "non" and "non-geo".
#
my $serverVar = "rtmpe://vod-non-geo.mediaworks.co.nz/vod/_definst_";
if ($geo eq "geo") {
$serverVar = "rtmpe://vod-geo.mediaworks.co.nz/vod/_definst_";
}
my $locationVar = "mp4:" . $sloc . "/" . $replace;
my $info = undef;
{
my $smil = $smilPath . "?serverVar=" . $serverVar .
"&locationVar=" . $locationVar . "&typeVar=mp4";
debug "Trying to get SMIL: $smil";
my $smilResponse = $browser->get($smil);
die "Failed to get SMIL" if !$smilResponse->is_success();
my $smilContent = $smilResponse->decoded_content();
#open(F, "> smil.xml");print F $smilContent;close(F);
my $xml = $smilContent;
my %rateMap = ();
while ($xml =~ s/\<video src=\"([^\"]+)" system-bitrate=\"(\d+)\"//s) {
my $url = $1;
my $bps = $2;
debug "Available rate of ${bps} from $url";
$rateMap{$bps} = { rate => $bps, src => $url };
}
my $quality = $prefs->{quality};
$quality = "default" if !defined($quality);
$info = $rateMap{$quality};
if (!defined($info)) {
my @rates = map { $rateMap{$_} } sort { $a <=> $b } keys %rateMap;
my $option = undef;
foreach my $try ("high", "medium", "low") {
$option = pop(@rates) if (scalar(@rates) > 0);
if ($try eq $quality) {
# Matched
$info = $option;
last;
}
if (!defined($info)) {
# Default to highest quality if no match seen.
$info = $option;
}
}
}
if (!defined($info)) {
die "Couldn't match the requested quality";
}
debug "Matching \"$quality\" quality at " . $info->{rate} .
"bps with source \"" . $info->{src} . "\"";
}
my $rtmp = $serverVar . "/" . $info->{src};
# It seems to be necessary to use --live, otherwise the stream
# periodically jumps backwards.
return {
rtmp => $rtmp,
live => "",
token => $secureToken,
swfVfy => "http://wa2.static.mediaworks.co.nz/video/jw/6.60/jwplayer.flash.swf",
flv => $filename
};
}
sub can_handle {
my($self, $browser, $url) = @_;
my $slocRE = quotemeta($self->getSloc());
return $url && URI->new($url)->host =~ m/(?:^|\.)$slocRE\.co\.nz$/;
}
1;
|