Any update? Or does anyone know of any tool that allows restricting the download size?
I am also trying to write a tool to automate analysis of flv files on the web. The clip analysis can be done with a header preview, so I want similar functionality to avoid full download.
Best regards,
-Avid (seeker of perl wisdom)
| [reply] |
LWP::UserAgent has a max_size method that can limit the size that will be retrieved to a fixed number of bytes.
Or you can be more ambitious and pass a :content_cb callback to the get method. This will give you the response in chunks and you can then accumulate them in a variable. When your analysis says that you have enough you can die to end the request, and catch that at a higher level with an eval. This will be a lot more complex, but avoids having to guess how much of the file to download.
| [reply] |
Hi funstence.
I wrote a simple program that you might find useful.
#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;
my $file = 'test.txt';
my $content = get('http://www. google.com');
open FH, " >", "$file" or die "Error: $!\n";
print FH $content until -s $file >= 25;
# I routinely include code to check for a successful closing
# of the filehandle since a hardware error could occur.
close FH or die "Error: $!\n";
Hope this helps,
~Katie
| [reply] [d/l] |