X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=videosite%2FFileGetter.pm;h=5e54935c15076aecbb5368fc3d71bf3a964500e4;hb=HEAD;hp=a01c2857df727155609ecca7847990a58e407aa6;hpb=d738e03f4f2d70a41eba8b77177826d1ff62f42b;p=videosite.git diff --git a/videosite/FileGetter.pm b/videosite/FileGetter.pm index a01c285..5e54935 100644 --- a/videosite/FileGetter.pm +++ b/videosite/FileGetter.pm @@ -1,23 +1,29 @@ -package FileGetter; +# (c) 2007 by Ralf Ertzinger +# licensed under GNU GPL v2 +# +# A getter which will download the media to a local file storage +# -use GetterBase; -@ISA = qw(GetterBase); +package videosite::FileGetter; + +use videosite::GetterBase; +@ISA = qw(videosite::GetterBase); use strict; -use LWP::Simple qw(!get); use File::Basename; sub new { my $class = shift; - my $self = $class->SUPER::new(); - - $self->{'NAME'} = 'filegetter'; - $self->{'_PARAMS'} = {'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 _)"]}; - - bless($self, $class); - $self->_prepare_parameters(); - - return $self; + my $self = $class->SUPER::new( + NAME => 'filegetter', + _PARAMS => { + 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); } sub get { @@ -27,7 +33,7 @@ sub get { my $dirname; $dlfile = sprintf($self->_getval('FILEPATTERN'), - $self->_encode($video->{'TYPE'}), + $self->_encode($video->{'SOURCE'}), $self->_encode($video->{'ID'}), $self->_encode($video->{'TITLE'}), $self->_encode($video->{'DLURL'}), @@ -39,17 +45,42 @@ sub get { return 0; } - $self->debug('Going to download %s to %s', $video->{'DLURL'}, $dlfile); + if (exists($video->{'CONNECTOR'})) { + $self->selectconn($video->{'CONNECTOR'}); + } - if (200 != LWP::Simple::mirror($video->{'DLURL'}, $dlfile)) { - $self->error('Could not download %s to %s', $video->{'DLURL'}, $dlfile); - return 0; + + $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)', $dlurl, $dlfile, $res->code()); + return 0; + } + + return 1; +} + sub _encode { my $self = shift; my $s = shift;