diff options
author | Nigel Taylor <njtaylor0101@gmail.com> | 2013-03-04 16:40:06 -0800 |
---|---|---|
committer | Nigel Taylor <njtaylor0101@gmail.com> | 2013-03-04 16:40:06 -0800 |
commit | 7c20f3e3757e3651d8fbb3bc1868763f36faa239 (patch) | |
tree | c8d1557eb244e180f16ea757f73699cd9d2de3ff | |
parent | cb0b604410914f391c2655e724052bc60c329d6c (diff) | |
parent | 16b93aa63ae5913cfdec37f4445e7b63b46f70c9 (diff) | |
download | get-flash-videos-7c20f3e3757e3651d8fbb3bc1868763f36faa239.tar.gz |
Merge pull request #98 from njtaylor/master
Fixes for ITV, Channel 4, Ustream
-rw-r--r-- | debian/control | 30 | ||||
-rw-r--r-- | lib/FlashVideo/Site/Channel4.pm | 102 | ||||
-rw-r--r-- | lib/FlashVideo/Site/Googlevideosearch.pm | 2 | ||||
-rw-r--r-- | lib/FlashVideo/Site/Itv.pm | 27 | ||||
-rw-r--r-- | lib/FlashVideo/Site/Ustream.pm | 5 |
5 files changed, 125 insertions, 41 deletions
diff --git a/debian/control b/debian/control index 76cc42c..2f94fb9 100644 --- a/debian/control +++ b/debian/control @@ -2,17 +2,37 @@ Source: libapp-get-flash-videos-perl Section: utils Priority: optional Build-Depends: debhelper (>= 7) -Build-Depends-Indep: perl, libwww-perl, liburi-perl, libtie-ixhash-perl, - libwww-mechanize-perl +Build-Depends-Indep: libmodule-find-perl, + libtie-ixhash-perl, + liburi-perl, + libwww-mechanize-perl, + libwww-perl, + libxml-simple-perl, + perl Maintainer: Monsieur Video <monsieurvideo@gmail.com> Standards-Version: 3.8.3 Homepage: http://code.google.com/p/get-flash-videos/ Package: get-flash-videos Architecture: all -Depends: ${perl:Depends}, libwww-perl, liburi-perl, libwww-mechanize-perl -Recommends: libxml-simple-perl, libcompress-zlib-perl, - rtmpdump | flvstreamer, libdigest-sha-perl, liblwp-protocol-socks-perl +Depends: libcrypt-blowfish-perl, + libdata-amf-perl, + libhtml-parser-perl, + libhtml-tree-perl, + libmodule-find-perl, + libtie-ixhash-perl, + liburi-perl, + libwww-mechanize-perl, + libwww-perl, + rtmpdump, + ${misc:Depends}, + ${perl:Depends} +Recommends: get_iplayer, + ffmpeg | libav-tools, + libcrypt-rijndeal-perl, + liblwp-protocol-socks-perl, + libxml-simple-perl +Suggests: mplayer Description: Video downloader for various Flash-based video hosting sites Download videos from various Flash-based video hosting sites, without having to use the Flash player. Handy for saving viqeos for watching offline, and diff --git a/lib/FlashVideo/Site/Channel4.pm b/lib/FlashVideo/Site/Channel4.pm index 9f064df..0dd7b91 100644 --- a/lib/FlashVideo/Site/Channel4.pm +++ b/lib/FlashVideo/Site/Channel4.pm @@ -7,16 +7,25 @@ use strict; use Crypt::Blowfish_PP; use FlashVideo::Utils; +use FlashVideo::JSON; use MIME::Base64; +use Time::HiRes qw(time); use constant TOKEN_DECRYPT_KEY => 'STINGMIMI'; -our $VERSION = '0.01'; +our $VERSION = '0.04'; sub Version() { $VERSION;} sub find_video { my ($self, $browser, $embed_url, $prefs) = @_; + + if ($browser->response->is_redirect) { + my $relurl = $browser->response->header('Location'); + info "Relocated to $relurl"; + $browser->get($relurl); + } + my $page_url = $browser->uri->as_string; # Determine series and episode. Channel 4 sometimes have these backwards, @@ -28,6 +37,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 +78,77 @@ 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"; + my @entries; + if (ref($json->{feed}->{entry}) eq "ARRAY") { + @entries = @{$json->{feed}->{entry}}; + } + else + { + $entries[0] = $json->{feed}->{entry}; + } + foreach my $entry ( @entries ) { + 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 +156,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}; diff --git a/lib/FlashVideo/Site/Googlevideosearch.pm b/lib/FlashVideo/Site/Googlevideosearch.pm index 9eb9c34..e99b27c 100644 --- a/lib/FlashVideo/Site/Googlevideosearch.pm +++ b/lib/FlashVideo/Site/Googlevideosearch.pm @@ -10,6 +10,8 @@ sub search { my($self, $search, $type) = @_; my $browser = FlashVideo::Mechanize->new; + + $browser->allow_redirects; $browser->get('http://video.google.com/videoadvancedsearch'); diff --git a/lib/FlashVideo/Site/Itv.pm b/lib/FlashVideo/Site/Itv.pm index 5242302..525ec4b 100644 --- a/lib/FlashVideo/Site/Itv.pm +++ b/lib/FlashVideo/Site/Itv.pm @@ -6,7 +6,7 @@ use FlashVideo::Utils; use HTML::Entities; use Encode; -our $VERSION = '0.02'; +our $VERSION = '0.03'; sub Version() { $VERSION;} sub find_video { @@ -172,19 +172,20 @@ EOF if (!$browser->success) { info "Couldn't download Itv subtitles: " . $browser->response->status_line; } - my $subtitles_ttml = $flv; - my $subtext = $browser->content; - my $istart = index $subtext, "<"; - $subtext = substr($subtext, $istart) unless ($istart < 0); - $subtext =~ s/UTF-16/utf8/; - - $subtitles_ttml =~ s/\.flv$/\.ttml/; +# Code to save .ttml file +# my $subtitles_ttml = $flv; +# my $subtext = $browser->content; +# my $istart = index $subtext, "<"; +# $subtext = substr($subtext, $istart) unless ($istart < 0); +# $subtext =~ s/UTF-16/utf8/; + +# $subtitles_ttml =~ s/\.flv$/\.ttml/; - unlink($subtitles_ttml); - open my $fh, ">", $subtitles_ttml; - binmode $fh; - print $fh $subtext; - close $fh; +# unlink($subtitles_ttml); +# open my $fh, ">", $subtitles_ttml; +# binmode $fh; +# print $fh $subtext; +# close $fh; my $subtitles_file = $flv; $subtitles_file =~ s/\.flv$/\.srt/; diff --git a/lib/FlashVideo/Site/Ustream.pm b/lib/FlashVideo/Site/Ustream.pm index 7674e91..b9b4b21 100644 --- a/lib/FlashVideo/Site/Ustream.pm +++ b/lib/FlashVideo/Site/Ustream.pm @@ -5,6 +5,9 @@ use strict; use FlashVideo::Utils; use MIME::Base64; +our $VERSION = '0.01'; +sub Version() { $VERSION }; + sub find_video { my ($self, $browser, $embed_url) = @_; @@ -42,6 +45,8 @@ EOF # Data::AMF fails to understand this response, so just parse ourselves. my($flv_url) = $browser->content =~ /flv.{3,5}(http:[^\0]+)/; + $browser->allow_redirects; + return $flv_url, title_to_filename($title); } |