fix quoting in AsyncWgetFileGetter again
[videosite.git] / videosite / FileGetter.pm
index 0d2b250..5e54935 100644 (file)
@@ -20,6 +20,7 @@ sub new {
             MINFREE => ['500000', 'The amount of space that needs to be available on the filesystem before the video is downloaded (in kilobytes)'],
             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 _)"]
         },
+        @_,
     );
 
     return bless($self, $class);
@@ -30,8 +31,6 @@ sub get {
     my $video = shift;
     my $dlfile;
     my $dirname;
-    my $ua;
-    my $res;
 
     $dlfile = sprintf($self->_getval('FILEPATTERN'),
         $self->_encode($video->{'SOURCE'}),
@@ -49,20 +48,39 @@ sub get {
     if (exists($video->{'CONNECTOR'})) {
         $self->selectconn($video->{'CONNECTOR'});
     }
-    $ua = $self->ua();
 
-    $self->debug('Going to download %s to %s', $video->{'DLURL'}, $dlfile);
 
-    $res = $ua->mirror($video->{'DLURL'}, $dlfile);
+    $self->_download( $video->{'DLURL'}, $dlfile, $video )
+       or return 0;
+
+    if (exists($video->{'DLURL_AUDIO'})) {
+        $self->_download( $video->{'DLURL_AUDIO'}, $dlfile . '.audio', $video )
+           or return 0;
+    }
+
+    return 1;
+}
+
+
+sub _download {
+    my $self = shift;
+    my $dlurl = shift;
+    my $dlfile = shift;
+    my $video = shift;
+    my $res;
+
+    $self->debug('Going to download %s to %s', $dlurl, $dlfile);
+
+    $res = $self->ua()->mirror($dlurl, $dlfile);
+    
     if (!$res->is_success()) {
-        $self->error('Could not download %s to %s (%s)', $video->{'DLURL'}, $dlfile, $res->code());
+        $self->error('Could not download %s to %s (%s)', $dlurl, $dlfile, $res->code());
         return 0;
     }
 
     return 1;
 }
 
-
 sub _encode {
     my $self = shift;
     my $s = shift;