Skip to content
Browse files

Add -m to limit download size

Some files can be huge.  Users may want to limit max download size.
  • Loading branch information...
1 parent e9fba76 commit 06120a06937452139c6da12d1d0d8896f18e11b5 @singpolyma committed May 3, 2010
Showing with 20 additions and 1 deletion.
  1. +11 −0 FlashVideo/Downloader.pm
  2. +5 −0 FlashVideo/RTMPDownloader.pm
  3. +4 −1 get_flash_videos
View
11 FlashVideo/Downloader.pm
@@ -125,6 +125,11 @@ sub download {
':content_cb' => sub {
my ($data, $response) = @_;
+ if($::opt{max_size} && $response->header('Content-Length') && $response->header('Content-Length') > $::opt{max_size}) {
+ print "File exceeds your max size of " . $::opt{max_size} . " bytes. Aborting.\n";
+ exit;
+ }
+
# If we're resuming, Content-Length will just be the length of the
# range the server is sending back, so add on the offset to make %
# completed accurate.
@@ -189,6 +194,12 @@ sub download {
$self->{downloaded} += $len;
$self->progress;
+
+ if($::opt{max_size} && $self->{downloaded} > $::opt{max_size}) {
+ print "File exceeds your max size: " . $::opt{max_size} . " bytes. Aborting.\n";
+ exit;
+ }
+
}, ':read_size_hint' => 16384);
if($browser->response->header("X-Died")) {
View
5 FlashVideo/RTMPDownloader.pm
@@ -185,6 +185,11 @@ sub run {
if(defined $self->{stream} && $self->{downloaded} > 300_000) {
$self->{stream}->();
}
+
+ if($::opt{max_size} && $self->{downloaded} > $::opt{max_size}) {
+ print "File exceeds your max size of " . $::opt{max_size} . " bytes. Aborting.\n";
+ exit;
+ }
}
waitpid $pid, 0;
View
5 get_flash_videos
@@ -65,7 +65,8 @@ BEGIN {
quiet => 0,
quality => "high",
subtitles => 0,
- info => 0
+ info => 0,
+ max_size => 0
);
}
@@ -96,6 +97,7 @@ Options:
-v --version Print version.
-y --yes Say yes to any questions (don't prompt for any information).
-i --info Print out info about video instead of downloading.
+ -m --max-size Maximum number of bytes to download.
EOF
@@ -136,6 +138,7 @@ GetOptions(
"quality|r=s" => \$opt{quality},
"subtitles" => \$opt{subtitles},
"info|i" => \$opt{info},
+ "max-size|m=s" => \$opt{max_size}
) or die "Try $0 --help for more information.\n";
if($opt{version}) {

0 comments on commit 06120a0

Please sign in to comment.
Something went wrong with that request. Please try again.