X-Git-Url: https://git.camperquake.de/gitweb.cgi?p=videosite.git;a=blobdiff_plain;f=videosite-dl.pl;h=46c8b49eb0718f7678f2bed562c1a220ceabebe9;hp=ea7b99931f4eb08d6ffdbf7f033b22ce7efe4ae4;hb=01fc17a9fd2a11cd5826a2581fe662e96ac5912c;hpb=956c646c9b8521ecd81dee161f31307421ca9f27 diff --git a/videosite-dl.pl b/videosite-dl.pl index ea7b999..46c8b49 100755 --- a/videosite-dl.pl +++ b/videosite-dl.pl @@ -4,78 +4,58 @@ 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 = (); +my $info = 0; +my $debug = 0; +my %config = ( + mode => 'download', + getter => 'filegetter', + 'plugin.youtube.QUALITY' => 'hd', + 'plugin.filegetter.FILEPATTERN' => './%3$s.flv', +); - unshift(@INC, $dir); +sub link_callback { + my $m = shift; - 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 $p; }; - if ($@) { - print("Failed to load plugin: $@"); - next; - } - - $g = eval $p.q{->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}); + if ($info) { + foreach (keys(%{$m})) { + printf("%s: %s\n", $_, defined($m->{$_})?$m->{$_}:'(undef)'); } + return 1; + } else { + print("Downloading $m->{'TITLE'}\n"); + return 0; } - - return @g; } -my $hq = 0; -my $ext = '.flv'; -my $y; -my $f; -my $m; -my @g; -my $bp; -# 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'); +GetOptions("i" => \$info, "d" => \$debug); -@g = ploader($bp, '.*Grabber\.pm$', 'grabber'); -($f) = ploader($bp, '^FileGetter\.pm$', 'getter'); +push(@INC, dirname(realpath($0))); +load 'libvideosite'; -unless(defined(@g) and defined($f)) { - print("No plugins could be loaded\n"); - exit 1; +unless(libvideosite::register_api({ + link_callback => \&link_callback, + _config_default => sub { return \%config }, + _debug => sub { return $debug }, +})) { + die("Error registering API: $libvideosite::error"); } -$f->setval('FILEPATTERN', './%3$s' . $ext); +unless(libvideosite::init()) { + die("Could not init libvideosite: $libvideosite::error"); +} foreach (@ARGV) { - foreach $y (@g) { - ($m, undef) = $y->get($_); - if (defined($m)) { - print("Downloading $m->{'TITLE'}\n"); - $f->get($m); - } - } + printf("Handling %s...\n", $_); + libvideosite::check_for_link({ + message => $_, + ewpf => sub { print @_, "\n" }, + window => "", + }); }