7 use LWP::Simple qw(!get);
12 my $self = $class->SUPER::new();
14 $self->{'NAME'} = 'filegetter';
15 $self->{'_PARAMS'} = {'MINFREE' => ['500000', 'The amount of space that needs to be available on the filesystem before the video is downloaded (in kilobytes)'], 'FILEPATTERN', => ['/tmp/%s - %s - %s.flv', "The file name to save the file under. This is a string which is passed to a sprintf call later on. The parameters passed to that sprintf call, in order, are:\n- The site the video is from\n- The ID of the video\n- The title of the video\n- The URL of the video file itself\n- The URL of the site the video was taken from\nAll parameters are encoded (space and / replaced by _)"]};
18 $self->_prepare_parameters();
29 $dlfile = sprintf($self->_getval('FILEPATTERN'),
30 $self->_encode($video->{'TYPE'}),
31 $self->_encode($video->{'ID'}),
32 $self->_encode($video->{'TITLE'}),
33 $self->_encode($video->{'DLURL'}),
34 $self->_encode($video)->{'URL'});
36 $dirname = dirname($dlfile);
37 if ($self->_diskfree($dirname) < $self->_getval('MINFREE')) {
38 $self->error("Not enough free space to download");
42 $self->debug('Going to download %s to %s', $video->{'DLURL'}, $dlfile);
44 if (200 != LWP::Simple::mirror($video->{'DLURL'}, $dlfile)) {
45 $self->error('Could not download %s to %s', $video->{'DLURL'}, $dlfile);
65 # if you want it portable, use Filesys::Statvfs
71 open DF, "df -P $dir|" or return 0;
72 my $line = <DF>; # skip header
75 if ($line =~ /\s(\d+)\s+\d{1,3}% (\/.*)$/) {
79 $size = -1; #some error occurred