diff options
author | Nigel Taylor <njtaylor0101@gmail.com> | 2013-03-04 23:00:01 +0000 |
---|---|---|
committer | Nigel Taylor <njtaylor0101@gmail.com> | 2013-03-04 23:00:01 +0000 |
commit | 3389d808f883943965329e8cb7bece4c681b690b (patch) | |
tree | ce38f89667dcbeb01f9dfd9e0a557e7c993ea4fe | |
parent | 38a100d909fc653c51219df15ca980efb401edfc (diff) | |
parent | cb0b604410914f391c2655e724052bc60c329d6c (diff) | |
download | get-flash-videos-3389d808f883943965329e8cb7bece4c681b690b.tar.gz |
Merge branch 'master' of git://github.com/monsieurvideo/get-flash-videos
-rw-r--r-- | .gitignore | 7 | ||||
-rwxr-xr-x | get_flash_videos | 12 | ||||
-rw-r--r-- | lib/FlashVideo/FFmpegDownloader.pm | 39 | ||||
-rw-r--r-- | lib/FlashVideo/Site/Svtplay.pm | 100 |
4 files changed, 111 insertions, 47 deletions
@@ -21,3 +21,10 @@ MYMETA.* mk/makemaker.mk mk/makemaker.mk.old mk/makemaker-wrap.mk +# Emacs files +# +*~ +.#* +\#*\# +\#* +TAGS diff --git a/get_flash_videos b/get_flash_videos index 8a5c7f6..d98e56b 100755 --- a/get_flash_videos +++ b/get_flash_videos @@ -41,6 +41,7 @@ use FlashVideo::URLFinder; use FlashVideo::Mechanize; use FlashVideo::Downloader; use FlashVideo::RTMPDownloader; +use FlashVideo::FFmpegDownloader; use FlashVideo::Search; use FlashVideo::Utils; use FlashVideo::VideoPreferences; @@ -402,9 +403,14 @@ sub download { my $file = $save_as; if(ref $data eq 'HASH') { - # RTMP data - $downloader = FlashVideo::RTMPDownloader->new; - $file ||= $data->{flv}; + if (defined($data->{downloader}) && $data->{downloader} eq "ffmpeg") { + $downloader = FlashVideo::FFmpegDownloader->new; + $file ||= $data->{file}; + } else { + # RTMP data + $downloader = FlashVideo::RTMPDownloader->new; + $file ||= $data->{flv}; + } } else { # HTTP $downloader = FlashVideo::Downloader->new; diff --git a/lib/FlashVideo/FFmpegDownloader.pm b/lib/FlashVideo/FFmpegDownloader.pm new file mode 100644 index 0000000..7f11690 --- /dev/null +++ b/lib/FlashVideo/FFmpegDownloader.pm @@ -0,0 +1,39 @@ +# Part of get-flash-videos. See get_flash_videos for copyright. +package FlashVideo::FFmpegDownloader; + +use strict; +use warnings; +use base 'FlashVideo::Downloader'; +use FlashVideo::Utils; + +sub download { + my ($self, $ffmpeg_data, $file) = @_; + + $self->{printable_filename} = $file; + my $executable; + + # Look for executable (ffmpeg or avconv) + if (!is_program_on_path("ffmpeg")) { + if (!is_program_on_path("avconv")) { + die "Could not find ffmpeg nor avconv executable!"; + } else { + $executable = "avconv"; + } + } else { + $executable = "ffmpeg"; + } + + # Prepend the executable to the list of arguments + my @args = @{$ffmpeg_data->{args}}; + unshift @args, $executable; + + # Execute command + if (system(@args) != 0) { + die "Calling @args failed: $?"; + } + + # Return size of the downloaded file + return -s $file; +} + +1; diff --git a/lib/FlashVideo/Site/Svtplay.pm b/lib/FlashVideo/Site/Svtplay.pm index d64a356..e588a95 100644 --- a/lib/FlashVideo/Site/Svtplay.pm +++ b/lib/FlashVideo/Site/Svtplay.pm @@ -8,10 +8,13 @@ use FlashVideo::Utils; use FlashVideo::JSON; use HTML::Entities; +our $VERSION = '0.01'; +sub Version() { $VERSION;} + sub find_video { my ($self, $browser, $embed_url, $prefs) = @_; my @rtmpdump_commands; - + if ($browser->uri->as_string !~ m/video\/([0-9]*)/) { die "No video id found in url"; } @@ -20,7 +23,7 @@ sub find_video { my $name = decode_entities($1); my $info_url = "http://www.svtplay.se/video/$video_id?output=json"; $browser->get($info_url); - + if (!$browser->success) { die "Couldn't download $info_url: " . $browser->response->status_line; } @@ -42,42 +45,6 @@ sub find_video { } } - - # 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}) { if (my $subtitles_url = $video_data->{video}->{subtitleReferences}[0]->{url}) { info "Found subtitles URL: $subtitles_url"; @@ -88,7 +55,7 @@ sub find_video { info "Couldn't download subtitles: " . $browser->status_line; } - my $srt_filename = title_to_filename($name, "srt"); + my $srt_filename = title_to_filename($name, "srt"); open my $srt_fh, '>', $srt_filename or die "Can't open subtitles file $srt_filename: $!"; @@ -101,11 +68,56 @@ sub find_video { } } - return { - flv => title_to_filename($name, "flv"), - rtmp => $rtmp_url, - swfVfy => "http://www.svtplay.se/public/swf/video/svtplayer-2012.15.swf", - }; + # 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 $filename = title_to_filename($name, "mp4"); + + # Set the arguments for ffmpeg + my @ffmpeg_args = ( + "-i", "$video_url", + "-acodec", "copy", + "-vcodec", "copy", + "-absf", "aac_adtstoasc", + "-f", "mp4", + "$filename" + ); + + return { + downloader => "ffmpeg", + file => $filename, + args => \@ffmpeg_args + }; + } else { + return { + flv => title_to_filename($name, "flv"), + rtmp => $rtmp_url, + swfVfy => "http://www.svtplay.se/public/swf/video/svtplayer-2012.15.swf", + }; + } } 1; |