X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=videosite.git;a=blobdiff_plain;f=videosite-test.pl;h=1f3d146a11734f103a7d4b676ab02c882f005ad6;hp=a0b71b9eaab8df18b82e3454dfa9ae614171126c;hb=01fc17a9fd2a11cd5826a2581fe662e96ac5912c;hpb=a33c3a8a1fc98179619e13fd64bc5d2f3c2ddc4d diff --git a/videosite-test.pl b/videosite-test.pl index a0b71b9..1f3d146 100755 --- a/videosite-test.pl +++ b/videosite-test.pl @@ -4,105 +4,54 @@ use strict; use Getopt::Long; use File::Spec; use File::Basename; +use Module::Load; use Cwd qw(realpath); +use Carp; -sub ploader { +$SIG{ __DIE__ } = sub { Carp::confess( @_ ) }; - my $dir = shift; - my $pattern = shift; - my $type = shift; - my @list; - my $p; - my $g; - my @g = (); - - unshift(@INC, $dir); - - opendir(D, $dir) || return (); - @list = grep {/$pattern/ && -f File::Spec->catfile($dir, $_) } readdir(D); - closedir(D); - - foreach $p (@list) { - $p =~ s/\.pm$//; - eval qq{ require videosite::$p; }; - if ($@) { - print("Failed to load plugin: $@"); - next; - } - - $g = eval qq{ videosite::$p->new();}; - if ($@) { - print("Failed to instanciate: $@"); - delete($INC{$p}); - next; - } - - if ($type eq $g->{'TYPE'}) { - push(@g, $g); - } else { - printf('%s has wrong type (got %s, expected %s)', $p, $g->{'TYPE'}, $type); - delete($INC{$p}); - } - } - - return @g; +my $debug = 0; +my %config = ( + mode => 'download', + getter => 'filegetter', +); +my $success = 0; +my $fail = 0; +my $notest = 0; + +push(@INC, dirname(realpath($0))); +load 'libvideosite'; + +unless(libvideosite::register_api({ + _debug => sub { return $debug }, +})) { + die("Error registering API: $libvideosite::error"); } -sub connectors { - my $c = {-name => 'environment', -schemas => {}}; - - if (exists($ENV{'http_proxy'})) { - $c->{-schemas}->{'http'} = $ENV{'http_proxy'} - } - - if (exists($ENV{'https_proxy'})) { - $c->{-schemas}->{'https'} = $ENV{'https_proxy'} - } - - return ( $c ); +unless(libvideosite::init()) { + die("Could not init libvideosite: $libvideosite::error"); } +select(STDOUT); +$| = 1; +printf("Doing self tests:\n"); +foreach my $g (libvideosite::_grabbers()) { + my $r; -my $hq = 0; -my $ext = '.flv'; -my $y; -my $f; -my $m; -my @g; -my $bp; -my $debug = 0; -my ($success, $notest, $fail) = (0,0,0); - -GetOptions("d" => \$debug); - -# This is some dark magic to find out our real base directory, -# where we hope to find our plugins. -$bp = File::Spec->catdir(dirname(realpath($0)), 'videosite'); -unshift(@INC, dirname(realpath($0))); - -@g = ploader($bp, '.*Grabber\.pm$', 'grabber'); -($f) = ploader($bp, '^FileGetter\.pm$', 'getter'); - -unless(@g and defined($f)) { - print("No plugins could be loaded\n"); - exit 1; -} + if (@ARGV) { + my $found; -foreach (@g, $f) { - $_->setio(sub { printf(@_); print("\n"); } ); + # If there are grabber names given on the command line check + # the current name against that list and skip if not present + $found = grep { $_ eq $g->{'NAME'} } @ARGV; - if ($debug) { - $_->setdebug(1); - $_->setconn(\&connectors); + if ($found == 0) { + next; + } } -} - -printf("Doing self tests:\n"); -foreach(@g) { - my $r; - printf(" %s...", $_->{'NAME'}); - $r = $_->_selftest(); + printf(" %s...", $g->{'NAME'}); + $r = $g->_selftest(); if(defined($r)) { if ($r == 1) { printf(" OK\n");