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);
35 $dlfile = sprintf($self->_getval('FILEPATTERN'),
36 $self->_encode($video->{'SOURCE'}),
37 $self->_encode($video->{'ID'}),
38 $self->_encode($video->{'TITLE'}),
39 $self->_encode($video->{'DLURL'}),
40 $self->_encode($video)->{'URL'});
42 $dirname = dirname($dlfile);
43 if ($self->_diskfree($dirname) < $self->_getval('MINFREE')) {
44 $self->error("Not enough free space to download");
48 if (exists($video->{'CONNECTOR'})) {
49 $self->selectconn($video->{'CONNECTOR'});
53 $self->_download( $video->{'DLURL'}, $dlfile, $video )
56 if (exists($video->{'DLURL_AUDIO'})) {
57 $self->_download( $video->{'DLURL_AUDIO'}, $dlfile . '.audio', $video )
72 $self->debug('Going to download %s to %s', $dlurl, $dlfile);
74 $res = $self->ua()->mirror($dlurl, $dlfile);
76 if (!$res->is_success()) {
77 $self->error('Could not download %s to %s (%s)', $dlurl, $dlfile, $res->code());
96 # if you want it portable, use Filesys::Statvfs
102 open DF, "df -P $dir|" or return 0;
103 my $line = <DF>; # skip header
105 if ( $line = <DF> ) {
106 if ($line =~ /\s(\d+)\s+\d{1,3}% (\/.*)$/) {
110 $size = -1; #some error occurred