1 # (c) 2009 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
6 package videosite::VeohGrabber;
8 use videosite::GrabberBase;
9 @ISA = qw(videosite::GrabberBase);
18 my $self = $class->SUPER::new();
20 $self->{'NAME'} = 'veoh';
21 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*veoh.com/browse/videos/category/[^/]+/watch/([^/]+))'];
24 $self->_prepare_parameters();
35 my $p = XML::Simple->new();
44 $metadata->{'URL'} = $url;
45 $metadata->{'ID'} = $2;
46 $metadata->{'TYPE'} = 'video';
47 $metadata->{'SOURCE'} = $self->{'NAME'};
48 $metadata->{'TITLE'} = undef;
49 $metadata->{'DLURL'} = undef;
51 # Get the XML file containing the video metadata
52 unless(defined($content = $self->simple_get(sprintf('http://www.veoh.com/rest/v2/execute.xml?apiKey=5697781E-1C60-663B-FFD8-9B49D2B56D36&method=veoh.search.search&type=video&maxResults=1&permalink=%s&contentRatingId=1&', $2), $ua))) {
53 $self->error('Could not download XML metadata');
57 unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
58 $self->error('Could not parse XML metadata');
62 if (exists($t->{'rsp'}->{'videoList'}->{'video'}->{'fullPreviewHashPath'})) {
63 $dlurl = $t->{'rsp'}->{'videoList'}->{'video'}->{'fullPreviewHashPath'};
65 $dlurl = $t->{'rsp'}->{'videoList'}->{'video'}->{'fullPreviewHashLowPath'}
68 unless(defined($dlurl)) {
69 $self->error('No dlurl found in XML');
73 # We now have to fetch the dlurl to get the redirect target after it,
74 # because the dlurl itself must be called with the right referer set
77 $r = $ua->get($dlurl, 'referer' => 'http://www.veoh.com');
79 unless ($r->is_redirect) {
80 $self->error('Expected redirect, got %s', $r->code);
84 $metadata->{'DLURL'} = $r->header('Location');
85 $metadata->{'TITLE'} = $t->{'rsp'}->{'videoList'}->{'video'}->{'title'};
87 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
88 $self->error('Could not extract download URL and title');