diff options
author | Matthew Bauer <mjbauer95@gmail.com> | 2012-11-21 22:11:02 -0600 |
---|---|---|
committer | Matthew Bauer <mjbauer95@gmail.com> | 2012-11-21 22:11:02 -0600 |
commit | 51d0ecfce84040350f25b9aa12c4c84e1d24415a (patch) | |
tree | 10e490c80f7d876c82e9f319ababe6f704b8bed9 | |
parent | 42c62fc05edaaf5b57f00bdfd5f1e74247cc3a2c (diff) | |
parent | dc5f34306a3ac7dbd0037d7f16ce737b0686d009 (diff) | |
download | get-flash-videos-51d0ecfce84040350f25b9aa12c4c84e1d24415a.tar.gz |
Merge github.com:monsieurvideo/get-flash-videos
-rw-r--r-- | lib/FlashVideo/Mechanize.pm | 21 | ||||
-rw-r--r-- | lib/FlashVideo/Site/Ima.pm | 5 | ||||
-rw-r--r-- | lib/FlashVideo/Site/Kanal5play.pm | 2 | ||||
-rw-r--r-- | lib/FlashVideo/Site/Svtplay.pm | 42 | ||||
-rw-r--r-- | lib/FlashVideo/Site/Vimeo.pm | 3 | ||||
-rw-r--r-- | lib/FlashVideo/Site/Youtube.pm | 2 | ||||
-rw-r--r-- | utils/combine-head | 2 |
7 files changed, 64 insertions, 13 deletions
diff --git a/lib/FlashVideo/Mechanize.pm b/lib/FlashVideo/Mechanize.pm index bc799db..649a21d 100644 --- a/lib/FlashVideo/Mechanize.pm +++ b/lib/FlashVideo/Mechanize.pm @@ -1,6 +1,7 @@ # Part of get-flash-videos. See get_flash_videos for copyright. package FlashVideo::Mechanize; use WWW::Mechanize; +use LWP::Protocol::https; use FlashVideo::Downloader; use Encode (); @@ -15,23 +16,27 @@ sub new { my $proxy = $App::get_flash_videos::opt{proxy}; if ($proxy) { - if ($proxy =~ /^(\w+):?(\d+)?$/) { + if ($proxy =~ m%^(\w+://)?([.\w-]+)(:\d+)?$%) { # Proxy is in format: # localhost:1337 # localhost + # [socks|http|...]://localhost:8080 # Add a scheme so LWP can use it. # Other formats are passed to LWP directly. - my ($host, $port) = ($1, $2); + my ($scheme, $host, $port) = ($1, $2, $3); - $port ||= 1080; # socks by default + $scheme ||= "socks://"; + my $sndport = ":8080"; + $sndport = ":1080" if ($scheme =~ /socks/); + $port ||= $sndport; # socks by default - $proxy = "socks://$host:$port"; + $proxy = $scheme.$host.$port; - print STDERR "Using proxy server $proxy\n" - if $App::get_flash_videos::opt{debug}; - - $browser->proxy([qw[http https]] => $proxy); } + print STDERR "Using proxy server $proxy\n" + if $App::get_flash_videos::opt{debug}; + + $browser->proxy([qw[http https]] => $proxy); } if($browser->get_socks_proxy) { diff --git a/lib/FlashVideo/Site/Ima.pm b/lib/FlashVideo/Site/Ima.pm index a928e16..54a35c9 100644 --- a/lib/FlashVideo/Site/Ima.pm +++ b/lib/FlashVideo/Site/Ima.pm @@ -24,9 +24,10 @@ sub find_video { } sub can_handle { - my($self, $browser) = @_; + my($self, $browser, $url) = @_; - return $browser->uri->host =~ /ima\.umn\.edu/i; + my $host = URI->new($url)->host; + return $host =~ /ima\.umn\.edu/i; } 1; diff --git a/lib/FlashVideo/Site/Kanal5play.pm b/lib/FlashVideo/Site/Kanal5play.pm index 2b37ea8..b750efe 100644 --- a/lib/FlashVideo/Site/Kanal5play.pm +++ b/lib/FlashVideo/Site/Kanal5play.pm @@ -36,7 +36,7 @@ sub find_video { my ($playpath) = $json->{streams}[0]->{source}; my $i; - foreach $i (keys @{ $json->{streams} }) { + foreach $i (keys %{ $json->{streams} }) { my ($rate) = int($json->{streams}[$i]->{bitrate}); if($bitrates->{$prefs->{quality}} == $rate){ $playpath = $json->{streams}[$i]->{source}; diff --git a/lib/FlashVideo/Site/Svtplay.pm b/lib/FlashVideo/Site/Svtplay.pm index 56e3ec1..d64a356 100644 --- a/lib/FlashVideo/Site/Svtplay.pm +++ b/lib/FlashVideo/Site/Svtplay.pm @@ -26,8 +26,9 @@ sub find_video { } my $video_data = from_json($browser->content); - my $bitrate = 0; + my $bitrate = -1; my $rtmp_url; + my $m3u8 = ""; foreach my $video (@{ $video_data->{video}->{videoReferences} }) { my $rate = int $video->{bitrate}; @@ -36,6 +37,45 @@ sub find_video { $rtmp_url = $video->{url}; $bitrate = $rate; } + if ($video->{url} =~ /.*\.m3u8/) { + $m3u8 = $video->{url}; + } + } + + + # If we found an m3u8 file we generate the ffmpeg download command + if (!($m3u8 eq "")) { + + $browser->get($m3u8); + + if (!$browser->success) { + die "Couldn't download $m3u8: " . $browser->response->status_line; + } + my @lines = split(/\r?\n/, $browser->content); + + $bitrate = -1; + my $video_url = ""; + my $i = 0; + + # Select highest bitrate available + foreach my $line (@lines) { + if ($line =~ /BANDWIDTH/) { + $line =~ /BANDWIDTH=([0-9]*),/; + my $this_rate = $1; + + if($bitrate < $this_rate) { + $video_url = $lines[$i + 1]; + $bitrate = $this_rate; + } + } + $i++; + } + + my $flv_filename = title_to_filename($name, "mp4"); + die "Not yet supported, use ffmpeg (http://ffmpeg.org/):\n\n" + . "ffmpeg -i '" . $video_url . "' -acodec copy -vcodec copy " + . "-absf aac_adtstoasc -f mp4 '" . $flv_filename . "'\n"; + } if ($prefs->{subtitles}) { diff --git a/lib/FlashVideo/Site/Vimeo.pm b/lib/FlashVideo/Site/Vimeo.pm index 34d6edf..cfff570 100644 --- a/lib/FlashVideo/Site/Vimeo.pm +++ b/lib/FlashVideo/Site/Vimeo.pm @@ -39,6 +39,9 @@ sub find_video { "&codecs=H264,VP8,VP6&type=moogaloop_local&embed_location="; my $filename = title_to_filename($title, "flv"); + $browser->get($url, Referer => $embed_url); + $url = $browser->response->header('Location'); + $browser->allow_redirects; return $url, $filename; diff --git a/lib/FlashVideo/Site/Youtube.pm b/lib/FlashVideo/Site/Youtube.pm index ce84859..0abcf15 100644 --- a/lib/FlashVideo/Site/Youtube.pm +++ b/lib/FlashVideo/Site/Youtube.pm @@ -67,7 +67,7 @@ sub find_video { my $video_id; if ($browser->content =~ /(?:var pageVideoId =|(?:CFG_)?VIDEO_ID'?\s*:)\s*'(.+?)'/ - || $browser->content =~ /video_id=([^&]+)/ + || $browser->content =~ /[&?]video_id=([^&"]+)/ || $embed_url =~ /v=([^&]+)/ || $browser->content =~ /&video_id=([^&]+)&/) { $video_id = $1; diff --git a/utils/combine-head b/utils/combine-head index 88da0d7..4c70027 100644 --- a/utils/combine-head +++ b/utils/combine-head @@ -13,6 +13,8 @@ use HTTP::Cookies (); use HTTP::Config (); use HTTP::Request::Common (); use LWP::Protocol::http (); +use LWP::Protocol::https (); +use Encode::Locale (); use XML::Simple (); use WWW::Mechanize::Link (); |