aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNigel Taylor <njtaylor0101@gmail.com>2013-03-03 01:58:20 +0000
committerNigel Taylor <njtaylor0101@gmail.com>2013-03-03 01:58:20 +0000
commitcfd81b6120f565883f3c87844cab989a68d74a80 (patch)
treec2cbe46e8dd6bcca5adc92064280375e4b94486d
parent078cbfdf8a5e65618a0adb52cbc63565d33d7d88 (diff)
downloadget-flash-videos-cfd81b6120f565883f3c87844cab989a68d74a80.tar.gz
Use search to find download for PS3, some are not within the +-5
range, and download would fail.
-rw-r--r--lib/FlashVideo/Site/Channel4.pm88
1 files changed, 65 insertions, 23 deletions
diff --git a/lib/FlashVideo/Site/Channel4.pm b/lib/FlashVideo/Site/Channel4.pm
index 9f064df..7a9ab19 100644
--- a/lib/FlashVideo/Site/Channel4.pm
+++ b/lib/FlashVideo/Site/Channel4.pm
@@ -7,11 +7,14 @@ use strict;
use Crypt::Blowfish_PP;
use FlashVideo::Utils;
+use FlashVideo::JSON;
use MIME::Base64;
+use Time::HiRes qw(time);
+use Data::Dumper;
use constant TOKEN_DECRYPT_KEY => 'STINGMIMI';
-our $VERSION = '0.01';
+our $VERSION = '0.02';
sub Version() { $VERSION;}
sub find_video {
@@ -28,6 +31,9 @@ sub find_video {
$series_and_episode = sprintf "S%02dE%02d", $1, $2;
}
+ # Create a uid
+ my $uid = int(time*1000);
+
# get SWF player file
my $swf_player;
if ($browser->content =~ /fourodPlayerFile\s+=\s+\'(4od\S+\.swf)\'/i) {
@@ -66,35 +72,69 @@ sub find_video {
my $lower_id = 0;
my $upper_id = 9999999;
if ($xml_ref->{assetInfo}->{uriData}->{streamUri} !~ /mp4$/ ) {
- for (my $off = 2; $off < 14; $off++) {
- my $asset_off = $off >> 1;
- $asset_off = -$asset_off if ($off & 1);
- $asset_off += $asset_id;
- if ($asset_off > $lower_id && $asset_off < $upper_id) {
- $raw_xml = $browser->get("http://ais.channel4.com/asset/$asset_off");
- if ($browser->success) {
- my $xml_off = from_xml($raw_xml);
- # Check Same programme
- if ( $xml_off->{assetInfo}->{brandTitle} eq $xml_ref->{assetInfo}->{brandTitle} &&
- $xml_off->{assetInfo}->{episodeTitle} eq $xml_ref->{assetInfo}->{episodeTitle} &&
- $xml_off->{assetInfo}->{programmeNumber} eq $xml_ref->{assetInfo}->{programmeNumber}) {
+
+ my $find_url = "http://ps3.channel4.com/pmlsd/" .
+ $xml_ref->{assetInfo}->{webSafeBrandTitle} .
+ "/4od.json?platform=ps3&uid=" . $uid;
+
+ $browser->get($find_url);
+ if ($browser->success) {
+ my $json = from_json($browser->content);
+
+ my $fstr = sprintf "%s/%03d", $xml_ref->{assetInfo}->{contractId},
+ $xml_ref->{assetInfo}->{programmeNumber};
+ info "Looking for programmeId $fstr";
+ foreach my $entry ( @{$json->{feed}->{entry}} ) {
+ if ($entry->{'dc:relation.programmeId'} eq $fstr) {
+ my $ps3_url = $entry->{group}->{player}->{'@url'};
+ info $entry->{'dc:relation.BrandTitle'} .
+ ' - ' . $entry->{title} .
+ ' Series ' . $entry->{'dc:relation.SeriesNumber'} .
+ ' Episode ' . $entry->{'dc:relation.EpisodeNumber'} .
+ ' ProgrammeId ' . $entry->{'dc:relation.programmeId'} .
+ ' Url ' . $ps3_url;
+ $raw_xml = $browser->get($ps3_url);
+ if ($browser->success) {
+ my $xml_off = from_xml($raw_xml);
if ($xml_off->{assetInfo}->{uriData}->{streamUri} =~ /mp4$/ ) {
$xml = $xml_off;
- info "Found mp4 stream asset id $asset_off siteSectionId $xml->{assetInfo}->{adverts}->{siteSectionId}";
- if ($xml->{assetInfo}->{uriData}->{streamUri} =~ /\.ps3-/ ) {
- last;
- }
+ info "Found mp4 stream url $ps3_url siteSectionId $xml->{assetInfo}->{adverts}->{siteSectionId}";
}
}
- else {
- if ($asset_off > $asset_id ) {
- $upper_id = $asset_off;
+ }
+ }
+
+ }
+ if (! defined($xml)) {
+ for (my $off = 2; $off < 20; $off++) {
+ my $asset_off = $off >> 1;
+ $asset_off = -$asset_off if ($off & 1);
+ $asset_off += $asset_id;
+ if ($asset_off > $lower_id && $asset_off < $upper_id) {
+ $raw_xml = $browser->get("http://ais.channel4.com/asset/$asset_off");
+ if ($browser->success) {
+ my $xml_off = from_xml($raw_xml);
+ # Check Same programme
+ if ( $xml_off->{assetInfo}->{brandTitle} eq $xml_ref->{assetInfo}->{brandTitle} &&
+ $xml_off->{assetInfo}->{programmeNumber} eq $xml_ref->{assetInfo}->{programmeNumber}) {
+ if ($xml_off->{assetInfo}->{uriData}->{streamUri} =~ /mp4$/ ) {
+ $xml = $xml_off;
+ info "Found mp4 stream asset id $asset_off siteSectionId $xml->{assetInfo}->{adverts}->{siteSectionId}";
+ if ($xml->{assetInfo}->{uriData}->{streamUri} =~ /\.ps3-/ ) {
+ last;
+ }
+ }
}
else {
- $lower_id = $asset_off;
+ if ($asset_off > $asset_id ) {
+ $upper_id = $asset_off;
+ }
+ else {
+ $lower_id = $asset_off;
+ }
}
- }
- }
+ }
+ }
}
}
}
@@ -102,6 +142,8 @@ sub find_video {
$xml = $xml_ref;
}
+ die "Unable to find suitable stream - may not be available yet\n" unless defined $xml;
+
my $stream_url = $xml->{assetInfo}->{uriData}->{streamUri};
my $token = $xml->{assetInfo}->{uriData}->{token};
my $cdn = $xml->{assetInfo}->{uriData}->{cdn};