- Adapt plugins to documentation
[videosite.git] / videosite / SevenloadGrabber.pm
1 package SevenloadGrabber;
2
3 use GrabberBase;
4 @ISA = qw(GrabberBase);
5
6 use LWP::Simple qw(!get);
7 use XML::Simple;
8 use Data::Dumper;
9
10 use strict;
11
12 sub new {
13     my $class = shift;
14     my $self = $class->SUPER::new();
15
16     $self->{'NAME'} = 'sevenload';
17     $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*sevenload.com/videos/([^/]+)(?:/.*)*)'];
18
19     bless($self, $class);
20     $self->_prepare_parameters();
21
22     return $self;
23 }
24
25 sub _parse {
26     my $self = shift;
27     my $url = shift;
28     my $pattern = shift;
29     my $content;
30     my $metadata = {};
31     my $p = XML::Simple->new();
32     my $t;
33
34     $url =~ m|$pattern|;
35     $url = $1;
36
37     $metadata->{'URL'} = $url;
38     $metadata->{'ID'} = $2;
39     $metadata->{'TYPE'} = 'video';
40     $metadata->{'SOURCE'} = 'sevenload';
41     $metadata->{'TITLE'} = undef;
42     $metadata->{'DLURL'} = undef;
43
44     # Get the XML file containing the video metadata
45     unless(defined($content = LWP::Simple::get(sprintf('http://api.sevenload.com/api/player/id/%s', $2)))) {
46         $self->error('Could not download XML metadata');
47         return undef;
48     }
49
50     unless(defined($t = $p->XMLin($content))) {
51         $self->error('Could not parse XML metadata');
52         return undef;
53     }
54
55     $metadata->{'DLURL'} = $t->{'item'}->{'video'}->{'url'};
56     $metadata->{'TITLE'} = $t->{'item'}->{'title'};
57
58     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
59         $self->error('Could not extract download URL and title');
60         return undef;
61     }
62
63     return $metadata;
64 }
65
66 1;