sub get {
my $self = shift;
my $video = shift;
- my $dlfile;
- my $dirname;
- my $cookie = "";
- my $useragent = "--user-agent=Mozilla/5.0";
-
- $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\" $useragent $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/([\\'])/\\$1/g; # ???
+
+ 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 '$video->{'DLURL'}' && mv '$tmpfile' '$dlfile' && chmod =rw '$dlfile' && touch '$dlfile' || rm -f '$tmpfile' ) & };
+ $self->debug("Going to execute: %s", $cmdline);
+ system($cmdline);
+
+ return 1;
+}