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);
11 use LWP::Simple qw(!get);
20 my $self = $class->SUPER::new();
22 $self->{'NAME'} = 'veoh';
23 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*veoh.com/browse/videos/category/[^/]+/watch/([^/]+))'];
26 $self->_prepare_parameters();
37 my $p = XML::Simple->new();
38 my $ua = LWP::UserAgent->new(max_redirect => 0);
46 $metadata->{'URL'} = $url;
47 $metadata->{'ID'} = $2;
48 $metadata->{'TYPE'} = 'video';
49 $metadata->{'SOURCE'} = $self->{'NAME'};
50 $metadata->{'TITLE'} = undef;
51 $metadata->{'DLURL'} = undef;
53 # Get the XML file containing the video metadata
54 unless(defined($content = LWP::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)))) {
55 $self->error('Could not download XML metadata');
59 unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
60 $self->error('Could not parse XML metadata');
64 if (exists($t->{'rsp'}->{'videoList'}->{'video'}->{'fullPreviewHashPath'})) {
65 $dlurl = $t->{'rsp'}->{'videoList'}->{'video'}->{'fullPreviewHashPath'};
67 $dlurl = $t->{'rsp'}->{'videoList'}->{'video'}->{'fullPreviewHashLowPath'}
70 unless(defined($dlurl)) {
71 $self->error('No dlurl found in XML');
75 # We now have to fetch the dlurl to get the redirect target after it,
76 # because the dlurl itself must be called with the right referer set
78 $r = $ua->get($dlurl, 'referer' => 'http://www.veoh.com');
80 unless ($r->is_redirect) {
81 $self->error('Expected redirect, got %s', $r->code);
85 $metadata->{'DLURL'} = $r->header('Location');
86 $metadata->{'TITLE'} = $t->{'rsp'}->{'videoList'}->{'video'}->{'title'};
88 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
89 $self->error('Could not extract download URL and title');