Base: Add simple_get() function
[videosite.git] / videosite / GrabberBase.pm
1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
3
4 package videosite::GrabberBase;
5 use videosite::Base;
6 @ISA = qw(videosite::Base);
7
8 use strict;
9
10 sub new {
11     my $class = shift;
12     my $self = $class->SUPER::new();
13
14     $self = {%{$self},
15         NAME => 'FlashGrab',
16         TYPE => 'grabber',
17         PATTERNS => [],
18     };
19     return bless($self, $class);
20 }
21
22 sub get($$) {
23     my $self = shift;
24     my $url = shift;
25     my $pattern;
26     my $res;
27
28     return undef unless $self->_getval('enabled');
29
30     foreach $pattern (@{$self->{'PATTERNS'}}) {
31         $self->debug("Matching %s against %s", $pattern, $url);
32         if ($url =~ m|$pattern|) {
33             $self->debug("Match");
34             foreach ($self->connectors()) {
35                 $self->debug("Using connector %s", $_->{'name'});
36                 $self->selectconn($_);
37                 $res = $self->_parse($url, $pattern);
38                 if (defined($res)) {
39                     $res->{'CONNECTOR'} = $_;
40                     last;
41                 }
42             }
43             return wantarray?($res, $pattern):$res;
44         }
45     }
46
47     return undef;
48 }
49
50 sub enable {
51     my $self = shift;
52
53     $self->debug('Enabling %s grabber', $self->{'NAME'});
54     $self->setval('enabled', '1');
55 }
56
57 sub disable {
58     my $self = shift;
59
60     $self->debug('Disabling %s grabber', $self->{'NAME'});
61     $self->setval('enabled', '0');
62 }
63
64 sub _parse {
65     my $self = shift;
66     my $url = shift;
67
68     return undef;
69 }
70
71 1;