videosite-test: Allow selective tests by using grabber names on the command line
[videosite.git] / videosite / AsyncWgetFileGetter.pm
index 43366a3..7a3642a 100644 (file)
@@ -1,6 +1,7 @@
 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
-#     2008-2009,2011 by Christian Garbs <mitch@cgarbs.de>
+#     2008-2009,2011-2012 by Christian Garbs <mitch@cgarbs.de>
 #     2010 by Maximilian Rehkopf <otakon@gmx.net>
+#
 # licensed under GNU GPL v2
 #
 # A getter which will download the media to a local file storage
@@ -19,14 +20,12 @@ use MIME::Base64;
 
 sub new {
     my $class = shift;
-    my $self = $class->SUPER::new();
-
-    $self->{'NAME'} = 'asyncwgetfilegetter';
+    my $self = $class->SUPER::new(
+        NAME => 'asyncwgetfilegetter',
+        @_,
+    );
 
-    bless($self, $class);
-    $self->_prepare_parameters();
-
-    return $self;
+    return bless($self, $class);
 }
 
 sub get {
@@ -35,6 +34,7 @@ sub get {
     my $dlfile;
     my $dirname;
     my $cookie = "";
+    my $useragent = "--user-agent=Mozilla/5.0";
 
     $dlfile = sprintf($self->_getval('FILEPATTERN'),
         $self->_encode($video->{'SOURCE'}),
@@ -43,6 +43,8 @@ sub get {
         $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");
@@ -66,7 +68,7 @@ sub get {
     }
     
     $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\" ) &";
+    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);