2 # A getter which will download the media to a local file storage
10 use LWP::Simple qw(!get);
15 my $self = $class->SUPER::new();
17 $self->{'NAME'} = 'filegetter';
18 $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 _)"]};
21 $self->_prepare_parameters();
32 $dlfile = sprintf($self->_getval('FILEPATTERN'),
33 $self->_encode($video->{'SOURCE'}),
34 $self->_encode($video->{'ID'}),
35 $self->_encode($video->{'TITLE'}),
36 $self->_encode($video->{'DLURL'}),
37 $self->_encode($video)->{'URL'});
39 $dirname = dirname($dlfile);
40 if ($self->_diskfree($dirname) < $self->_getval('MINFREE')) {
41 $self->error("Not enough free space to download");
45 $self->debug('Going to download %s to %s', $video->{'DLURL'}, $dlfile);
47 if (200 != LWP::Simple::mirror($video->{'DLURL'}, $dlfile)) {
48 $self->error('Could not download %s to %s', $video->{'DLURL'}, $dlfile);
68 # if you want it portable, use Filesys::Statvfs
74 open DF, "df -P $dir|" or return 0;
75 my $line = <DF>; # skip header
78 if ($line =~ /\s(\d+)\s+\d{1,3}% (\/.*)$/) {
82 $size = -1; #some error occurred