f58c00ef3e41f7120b5fef8ea1936abe7e5c975c
[videosite.git] / videosite / SevenloadGrabber.pm
1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
3 #
4 # Grabber for sevenload.com/de
5
6 package videosite::SevenloadGrabber;
7
8 use videosite::GrabberBase;
9 @ISA = qw(videosite::GrabberBase);
10
11 use XML::Simple;
12 use Data::Dumper;
13
14 use strict;
15
16 sub new {
17     my $class = shift;
18     my $self = $class->SUPER::new(
19         NAME => 'sevenload',
20         _SELFTESTURL => 'http://de.sevenload.com/videos/uqDvKzh-vilogo-TV-Spot',
21         _SELFTESTTITLE => 'vilogo TV-Spot',
22         PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*sevenload.com/videos/(\w+?)-.*)'],
23         @_,
24     );
25
26     return bless($self, $class);
27 }
28
29 sub _parse {
30     my $self = shift;
31     my $url = shift;
32     my $pattern = shift;
33     my $content;
34     my $metadata = {};
35     my $p = XML::Simple->new();
36     my $t;
37
38     $url =~ m|$pattern|;
39     $url = $1;
40
41     $metadata->{'URL'} = $url;
42     $metadata->{'ID'} = $2;
43     $metadata->{'TYPE'} = 'video';
44     $metadata->{'SOURCE'} = $self->{'NAME'};
45     $metadata->{'TITLE'} = undef;
46     $metadata->{'DLURL'} = undef;
47
48     # Get the XML file containing the video metadata
49     unless(defined($content = $self->simple_get(sprintf('http://flash.sevenload.com/player?itemId=%s', $2)))) {
50         $self->error('Could not download XML metadata');
51         return undef;
52     }
53
54     unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
55         $self->error('Could not parse XML metadata');
56         return undef;
57     }
58
59     # Loop through the video streams
60     foreach(@{$t->{'playerconfig'}->{'playlists'}->{'playlist'}->{'items'}->{'item'}->{'videos'}->{'video'}->{'streams'}->{'stream'}}) {
61         if ($_->{'quality'} eq 'high') {
62             $metadata->{'DLURL'} = $_->{'locations'}->{'location'}->{'content'};
63         }
64     }
65     $metadata->{'TITLE'} = $t->{'playerconfig'}->{'playlists'}->{'playlist'}->{'items'}->{'item'}->{'title'};
66
67     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
68         $self->error('Could not extract download URL and title');
69         return undef;
70     }
71
72     return $metadata;
73 }
74
75 1;