App-get_flash_videos
view release on metacpan or search on metacpan
get_flash_videos view on Meta::CPAN
if (/-/) {
my ($lower, $upper) = split /-/, $choice;
if ($upper > $lower and $upper > 0) {
push @download_urls, map { $results[$_]->{url} } $lower - 1 .. $upper - 1;
next;
}
else {
print STDERR "Search range '$_' is invalid.\n";
exit 1;
}
}
$_--;
if (!$results[$_]) {
print STDERR "'$_' is an invalid choice.\n";
exit 1;
}
push @download_urls, $results[$_]->{url};
}
}
}
else {
print STDERR "No results found for '$search'.\n";
exit 1;
}
}
else {
@download_urls = @urls;
}
my $download_count = 0;
# Construct a preferences object for these downloads, currently just based on
# the command line options.
my $prefs = FlashVideo::VideoPreferences->new(%opt);
foreach my $url (@download_urls) {
if (download($url, $prefs, @download_urls - $download_count)) {
$download_count++;
}
}
if($download_count == 0) {
info "Couldn't download any videos.";
exit 1;
} elsif($download_count != @download_urls) {
info "Problems downloading some videos.";
exit 2;
}
exit 0;
sub download {
my($url, $prefs, $remaining) = @_;
$url = "http://$url" if $url !~ m!^\w+:!;
# Might be downloading from a site that uses Brightcove or other similar
# Flash RTMP streaming server. These are handled differently. Need to get
# the page to determine this.
info "Downloading $url";
my $browser = FlashVideo::Mechanize->new;
$browser->get($url);
# (Redirect check is for Youtube which sometimes redirects to login page
# for "mature" videos.)
if (!$browser->success and !$browser->response->is_redirect) {
error "Couldn't download '$url': " . $browser->response->status_line;
}
# Figure out what package we need to use to get either the HTTP URL or
# rtmpdump data for the video.
my($package, $possible_url) = FlashVideo::URLFinder->find_package($url, $browser);
my($actual_url, @suggested_fnames) = eval {
$package->find_video($browser, $possible_url, $prefs);
};
if(!$actual_url) {
if($@ =~ /^Must have | requires /) {
my $error = "$@";
$error =~ s/at $0.*//;
print STDERR "$error" . REQ_INFO;
return 0;
} else {
print STDERR "Error: $@" . FRIENDLY_FAILURE;
return 0;
}
}
my $suggested_filename = $suggested_fnames[-1];
if (!$opt{play}) {
if (!$opt{yes} && @suggested_fnames > 1) {
print "There are different suggested filenames, please choose:\n";
my $count;
foreach my $filename (@suggested_fnames) {
$count++;
print "$count - $filename\n";
}
print "\nWhich filename would you like to use?: ";
chomp(my $chosen_fname = <STDIN>);
$suggested_filename = $suggested_fnames[$chosen_fname - 1] ||
$suggested_fnames[-1];
}
}
my $save_as = $opt{filename} || $suggested_filename;
my $action = $opt{play} ? "play" : "download";
for my $data((ref($actual_url) eq 'ARRAY' ? @$actual_url : $actual_url)) {
my $downloader;
my $file = $save_as;
if(ref $data eq 'HASH') {
# RTMP data
( run in 0.973 second using v1.01-cache-2.11-cpan-ceb78f64989 )