1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
4 # A getter which will download the media to a local file storage
7 package videosite::FileGetter;
9 use videosite::GetterBase;
10 @ISA = qw(videosite::GetterBase);
13 use LWP::Simple qw(!get);
18 my $self = $class->SUPER::new();
20 $self->{'NAME'} = 'filegetter';
21 $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 _)"]};
24 $self->_prepare_parameters();
36 $dlfile = sprintf($self->_getval('FILEPATTERN'),
37 $self->_encode($video->{'SOURCE'}),
38 $self->_encode($video->{'ID'}),
39 $self->_encode($video->{'TITLE'}),
40 $self->_encode($video->{'DLURL'}),
41 $self->_encode($video)->{'URL'});
43 $dirname = dirname($dlfile);
44 if ($self->_diskfree($dirname) < $self->_getval('MINFREE')) {
45 $self->error("Not enough free space to download");
49 $self->debug('Going to download %s to %s', $video->{'DLURL'}, $dlfile);
51 if (200 != ($res = LWP::Simple::mirror($video->{'DLURL'}, $dlfile))) {
52 $self->error('Could not download %s to %s (%s)', $video->{'DLURL'}, $dlfile, $res);
72 # if you want it portable, use Filesys::Statvfs
78 open DF, "df -P $dir|" or return 0;
79 my $line = <DF>; # skip header
82 if ($line =~ /\s(\d+)\s+\d{1,3}% (\/.*)$/) {
86 $size = -1; #some error occurred