- Add videosite-dl.pl, which allows downloads from the command line
authorRalf Ertzinger <sun@lain.camperquake.de>
Sat, 19 Apr 2008 12:09:18 +0000 (14:09 +0200)
committerRalf Ertzinger <sun@lain.camperquake.de>
Sat, 19 Apr 2008 12:09:18 +0000 (14:09 +0200)
videosite-dl.pl [new file with mode: 0755]

diff --git a/videosite-dl.pl b/videosite-dl.pl
new file mode 100755 (executable)
index 0000000..ea7b999
--- /dev/null
@@ -0,0 +1,81 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Getopt::Long;
+use File::Spec;
+use File::Basename;
+use Cwd qw(realpath);
+
+sub ploader {
+
+    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 $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});
+        }
+    }
+
+    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');
+
+@g = ploader($bp, '.*Grabber\.pm$', 'grabber');
+($f) = ploader($bp, '^FileGetter\.pm$', 'getter');
+
+unless(defined(@g) and defined($f)) {
+    print("No plugins could be loaded\n");
+    exit 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);
+        }
+    }
+}