Change new() function in plugins to avoid having to call _prepare_parameters() in...
[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     return bless($self, $class);
26 }
27
28 sub _parse {
29     my $self = shift;
30     my $url = shift;
31     my $pattern = shift;
32     my $content;
33     my $metadata = {};
34     my $p = XML::Simple->new();
35     my $t;
36
37     $url =~ m|$pattern|;
38     $url = $1;
39
40     $metadata->{'URL'} = $url;
41     $metadata->{'ID'} = $2;
42     $metadata->{'TYPE'} = 'video';
43     $metadata->{'SOURCE'} = $self->{'NAME'};
44     $metadata->{'TITLE'} = undef;
45     $metadata->{'DLURL'} = undef;
46
47     # Get the XML file containing the video metadata
48     unless(defined($content = $self->simple_get(sprintf('http://flash.sevenload.com/player?itemId=%s', $2)))) {
49         $self->error('Could not download XML metadata');
50         return undef;
51     }
52
53     unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
54         $self->error('Could not parse XML metadata');
55         return undef;
56     }
57
58     # Loop through the video streams
59     foreach(@{$t->{'playerconfig'}->{'playlists'}->{'playlist'}->{'items'}->{'item'}->{'videos'}->{'video'}->{'streams'}->{'stream'}}) {
60         if ($_->{'quality'} eq 'high') {
61             $metadata->{'DLURL'} = $_->{'locations'}->{'location'}->{'content'};
62         }
63     }
64     $metadata->{'TITLE'} = $t->{'playerconfig'}->{'playlists'}->{'playlist'}->{'items'}->{'item'}->{'title'};
65
66     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
67         $self->error('Could not extract download URL and title');
68         return undef;
69     }
70
71     return $metadata;
72 }
73
74 1;