fix quoting in AsyncWgetFileGetter again
[videosite.git] / videosite / AsyncFileGetter.pm
1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 #     2015 by Christian Garbs <mitch@cgarbs.de>
3 #
4 # licensed under GNU GPL v2
5 #
6 # A getter which will download the media to a local file storage
7 # in the background
8 #
9
10 package videosite::AsyncFileGetter;
11
12 use videosite::FileGetter;
13 @ISA = qw(videosite::FileGetter);
14
15 use strict;
16
17 sub new {
18     my $class = shift;
19     my $self = $class->SUPER::new(
20         NAME => 'asyncfilegetter',
21         @_,
22     );
23
24     return bless($self, $class);
25 }
26
27 sub _download {
28     my $self = shift;
29     my $dlurl = shift;
30     my $dlfile = shift;
31     my $video = shift;
32     my $child_pid;
33
34     # fork to background
35     $child_pid = fork();
36     
37     if ($child_pid) {               # parent
38         $self->debug('parent spawned process %d for download', $child_pid);
39         if (exists $self->{_API}->{wait_for_child}) {
40             $self->debug('calling wait_for_child on %d', $child_pid);
41             $self->{_API}->{wait_for_child}->($child_pid);
42         }
43         Irssi::pidwait_add($child_pid);
44     }
45     elsif (defined $child_pid) {    # child
46         close STDIN;
47         close STDOUT;
48         close STDERR;
49         $self->debug('CHILD: start download');
50         $self->SUPER::_download($dlurl, $dlfile, $video);
51         $self->debug('CHILD: end download');
52         exit;
53         $self->debug('CHILD: AFTER EXIT? WTF!');
54     }
55
56     return 1;
57 }
58