videosite-test: Allow selective tests by using grabber names on the command line
[videosite.git] / videosite-dl.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Getopt::Long;
5 use File::Spec;
6 use File::Basename;
7 use Module::Load;
8 use Cwd qw(realpath);
9
10 my $info = 0;
11 my $debug = 0;
12 my %config = (
13     mode => 'download',
14     getter => 'filegetter',
15     'plugin.youtube.QUALITY' => 'hd',
16     'plugin.filegetter.FILEPATTERN' => './%3$s.flv',
17 );
18
19 sub link_callback {
20     my $m = shift;
21
22     if ($info) {
23         foreach (keys(%{$m})) {
24             printf("%s: %s\n", $_, defined($m->{$_})?$m->{$_}:'(undef)');
25         }
26         return 1;
27     } else {
28         print("Downloading $m->{'TITLE'}\n");
29         return 0;
30     }
31 }
32
33
34 GetOptions("i" => \$info, "d" => \$debug);
35
36 push(@INC, dirname(realpath($0)));
37 load 'libvideosite';
38
39 unless(libvideosite::register_api({
40     config_init => sub {},
41     config_save => sub {},
42     config_get => sub { return $config{join(".", @{$_[0]})} },
43     config_set => sub { $config{join(".", @{$_[0]})} = $_[1] },
44     config_has => sub { exists($config{join(".", @{$_[0]})}) },
45     config_del => sub { delete($config{join(".", @{$_[0]})}) },
46     link_callback => \&link_callback,
47     _debug => sub { return $debug },
48 })) {
49     die("Error registering API: $libvideosite::error");
50 }
51
52 unless(libvideosite::init()) {
53     die("Could not init libvideosite: $libvideosite::error");
54 }
55
56 foreach (@ARGV) {
57     printf("Handling %s...\n", $_);
58     libvideosite::check_for_link({
59         message => $_,
60         ewpf => sub { print @_, "\n" },
61     });
62 }