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);
17 my $self = $class->SUPER::new(
20 MINFREE => ['500000', 'The amount of space that needs to be available on the filesystem before the video is downloaded (in kilobytes)'],
21 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 _)"]
26 return bless($self, $class);
37 $dlfile = sprintf($self->_getval('FILEPATTERN'),
38 $self->_encode($video->{'SOURCE'}),
39 $self->_encode($video->{'ID'}),
40 $self->_encode($video->{'TITLE'}),
41 $self->_encode($video->{'DLURL'}),
42 $self->_encode($video)->{'URL'});
44 $dirname = dirname($dlfile);
45 if ($self->_diskfree($dirname) < $self->_getval('MINFREE')) {
46 $self->error("Not enough free space to download");
50 if (exists($video->{'CONNECTOR'})) {
51 $self->selectconn($video->{'CONNECTOR'});
55 $self->debug('Going to download %s to %s', $video->{'DLURL'}, $dlfile);
57 $res = $ua->mirror($video->{'DLURL'}, $dlfile);
58 if (!$res->is_success()) {
59 $self->error('Could not download %s to %s (%s)', $video->{'DLURL'}, $dlfile, $res->code());
79 # if you want it portable, use Filesys::Statvfs
85 open DF, "df -P $dir|" or return 0;
86 my $line = <DF>; # skip header
89 if ($line =~ /\s(\d+)\s+\d{1,3}% (\/.*)$/) {
93 $size = -1; #some error occurred