Merge branch 'rertzinger/generic-load-save' into weechat
[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 use Carp;
10
11 $SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
12
13 my $info = 0;
14 my $debug = 0;
15 my %config = (
16     mode => 'download',
17     getter => 'filegetter',
18     'plugin.youtube.QUALITY' => 'hd',
19     'plugin.filegetter.FILEPATTERN' => './%3$s.flv',
20 );
21
22 sub link_callback {
23     my $m = shift;
24
25     if ($info) {
26         foreach (keys(%{$m})) {
27             printf("%s: %s\n", $_, defined($m->{$_})?$m->{$_}:'(undef)');
28         }
29         return 1;
30     } else {
31         print("Downloading $m->{'TITLE'}\n");
32         return 0;
33     }
34 }
35
36
37 GetOptions("i" => \$info, "d" => \$debug);
38
39 push(@INC, dirname(realpath($0)));
40 load 'libvideosite';
41
42 unless(libvideosite::register_api({
43     link_callback => \&link_callback,
44     _config_default => sub { return \%config },
45     _debug => sub { return $debug },
46 })) {
47     die("Error registering API: $libvideosite::error");
48 }
49
50 unless(libvideosite::init()) {
51     die("Could not init libvideosite: $libvideosite::error");
52 }
53
54 foreach (@ARGV) {
55     printf("Handling %s...\n", $_);
56     libvideosite::check_for_link({
57         message => $_,
58         ewpf => sub { print @_, "\n" },
59         window => "",
60     });
61 }