fix quoting in AsyncWgetFileGetter
[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 my @options;
22
23 sub link_callback {
24     my $m = shift;
25
26     if ($info) {
27         foreach (keys(%{$m})) {
28             printf("%s: %s\n", $_, defined($m->{$_})?$m->{$_}:'(undef)');
29         }
30         return 1;
31     } else {
32         print("Downloading $m->{'TITLE'}\n");
33         return 0;
34     }
35 }
36
37
38 GetOptions("i" => \$info, "d" => \$debug, "o=s" => \@options);
39 %config = (%config, map { split(/=/, $_, 2) } @options);
40
41 push(@INC, dirname(realpath($0)));
42 load 'libvideosite';
43
44 unless(libvideosite::register_api({
45     link_callback => \&link_callback,
46     _config_default => sub { return \%config },
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         io => sub { print @_, "\n" },
61         window => "",
62     });
63 }