X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=videosite-dl.pl;h=1b0079ca0b478e3aa2765f49c36bb553a3d16279;hb=66b5d05437a3112f7a716e372205613fa8beaa67;hp=ea7b99931f4eb08d6ffdbf7f033b22ce7efe4ae4;hpb=956c646c9b8521ecd81dee161f31307421ca9f27;p=videosite.git diff --git a/videosite-dl.pl b/videosite-dl.pl index ea7b999..1b0079c 100755 --- a/videosite-dl.pl +++ b/videosite-dl.pl @@ -24,13 +24,13 @@ sub ploader { foreach $p (@list) { $p =~ s/\.pm$//; - eval qq{ require $p; }; + eval qq{ require videosite::$p; }; if ($@) { print("Failed to load plugin: $@"); next; } - $g = eval $p.q{->new();}; + $g = eval qq{ videosite::$p->new();}; if ($@) { print("Failed to instanciate: $@"); delete($INC{$p}); @@ -48,6 +48,21 @@ sub ploader { return @g; } +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 ); +} + + my $hq = 0; my $ext = '.flv'; my $y; @@ -55,27 +70,47 @@ my $f; my $m; my @g; my $bp; +my $info = 0; +my $debug = 0; + +GetOptions("i" => \$info, "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(defined(@g) and defined($f)) { +unless(@g and defined($f)) { print("No plugins could be loaded\n"); exit 1; } +foreach (@g, $f) { + $_->setio(sub { printf(@_); print("\n"); } ); + $_->setconn(\&connectors); + + if ($debug) { + $_->setdebug(1); + } +} + $f->setval('FILEPATTERN', './%3$s' . $ext); foreach (@ARGV) { foreach $y (@g) { ($m, undef) = $y->get($_); if (defined($m)) { - print("Downloading $m->{'TITLE'}\n"); - $f->get($m); + if ($info) { + foreach (keys(%{$m})) { + printf("%s: %s\n", $_, defined($m->{$_})?$m->{$_}:'(undef)'); + } + } else { + print("Downloading $m->{'TITLE'}\n"); + $f->get($m); + } } } }