sub new {
my $class = shift;
- my $self = $class->SUPER::new();
+ my $self = $class->SUPER::new(
+ NAME => 'asyncwgetfilegetter',
+ @_,
+ );
- $self->{'NAME'} = 'asyncwgetfilegetter';
-
- bless($self, $class);
- $self->_prepare_parameters();
-
- return $self;
+ return bless($self, $class);
}
sub get {
my $self = shift;
my $video = shift;
- my $dlfile;
- my $dirname;
- my $cookie = "";
-
- $dlfile = sprintf($self->_getval('FILEPATTERN'),
- $self->_encode($video->{'SOURCE'}),
- $self->_encode($video->{'ID'}),
- $self->_encode($video->{'TITLE'}),
- $self->_encode($video->{'DLURL'}),
- $self->_encode($video)->{'URL'});
-
- $dlfile =~ s/([\\"])/\\$1/g;
-
- $dirname = dirname($dlfile);
- if ($self->_diskfree($dirname) < $self->_getval('MINFREE')) {
- $self->error("Not enough free space to download");
- return 0;
- }
-
- $self->debug('Going to download %s to %s', $video->{'DLURL'}, $dlfile);
-
- my (undef, $tmpfile) = tempfile('videosite.tmp.XXXXXXXXXXXX', DIR => $dirname);
+ # saving the environment has nice race conditions... :(
my %saved_env;
if (exists($video->{'CONNECTOR'})) {
$ENV{ $envkey } = $schemas->{$schemakey};
}
}
-
- $cookie = "--header=\"Cookie: $video->{'COOKIE'}\"" if (defined $video->{'COOKIE'});
- my $cmdline = "( wget -q -O\"$tmpfile\" $cookie \"$video->{'DLURL'}\" && mv \"$tmpfile\" \"$dlfile\" && chmod =rw \"$dlfile\" && touch \"$dlfile\" || rm -f \"$tmpfile\" ) &";
- $self->debug("Going to execute: %s", $cmdline);
- system($cmdline);
+
+ # dispatch to super class method
+ $self->SUPER::get($video);
# restore environment
foreach my $envkey (keys %saved_env) {
return 1;
}
+
+sub _download {
+ my $self = shift;
+ my $dlurl = shift;
+ my $dlfile = shift;
+ my $video = shift;
+ my $res;
+ my $cookie = '';
+ my $useragent = qq{ --user-agent='Mozilla/4.0 (compatible; MSIE 5.0; Linux) Opera 5.0 [en]' };
+
+ $dlfile =~ s/'/'"'"'/g; # escape ' as '"'"' (end current 'string', new "string" containing a ', start new 'string')
+
+ my (undef, $tmpfile) = tempfile('videosite.tmp.XXXXXXXXXXXX', DIR => dirname($dlfile));
+
+ $self->debug('Going to download %s to %s (%s)', $dlurl, $dlfile, $tmpfile);
+
+ $cookie = qq{ --header='Cookie: $video->{'COOKIE'}'} if (defined $video->{'COOKIE'});
+ my $cmdline = qq{ ( wget -q -O'$tmpfile' $useragent $cookie '$dlurl' && mv '$tmpfile' '$dlfile' && chmod =rw '$dlfile' && touch '$dlfile' || rm -f '$tmpfile' ) & };
+ $self->debug("Going to execute: %s", $cmdline);
+ system($cmdline);
+
+ return 1;
+}