# (c) 2007 by Ralf Ertzinger # 2015 by Christian Garbs # # licensed under GNU GPL v2 # # A getter which will download the media to a local file storage # in the background # package videosite::AsyncFileGetter; use videosite::FileGetter; @ISA = qw(videosite::FileGetter); use strict; sub new { my $class = shift; my $self = $class->SUPER::new( NAME => 'asyncfilegetter', @_, ); return bless($self, $class); } sub _download { my $self = shift; my $dlurl = shift; my $dlfile = shift; my $video = shift; my $child_pid; # fork to background $child_pid = fork(); if ($child_pid) { # parent $self->debug('parent spawned process %d for download', $child_pid); if (exists $self->{_API}->{wait_for_child}) { $self->debug('calling wait_for_child on %d', $child_pid); $self->{_API}->{wait_for_child}->($child_pid); } Irssi::pidwait_add($child_pid); } elsif (defined $child_pid) { # child close STDIN; close STDOUT; close STDERR; $self->debug('CHILD: start download'); $self->SUPER::_download($dlurl, $dlfile, $video); $self->debug('CHILD: end download'); exit; $self->debug('CHILD: AFTER EXIT? WTF!'); } return 1; }