Fix sevenload grabber
authorRalf Ertzinger <ralf@skytale.net>
Tue, 30 Apr 2013 20:06:15 +0000 (22:06 +0200)
committerRalf Ertzinger <ralf@skytale.net>
Tue, 30 Apr 2013 20:06:15 +0000 (22:06 +0200)
videosite/SevenloadGrabber.pm

index f58c00e..c36070a 100644 (file)
@@ -9,6 +9,7 @@ use videosite::GrabberBase;
 @ISA = qw(videosite::GrabberBase);
 
 use XML::Simple;
+use HTML::TokeParser;
 use Data::Dumper;
 
 use strict;
@@ -17,9 +18,9 @@ sub new {
     my $class = shift;
     my $self = $class->SUPER::new(
         NAME => 'sevenload',
-        _SELFTESTURL => 'http://de.sevenload.com/videos/uqDvKzh-vilogo-TV-Spot',
-        _SELFTESTTITLE => 'vilogo TV-Spot',
-        PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*sevenload.com/videos/(\w+?)-.*)'],
+        _SELFTESTURL => 'http://www.sevenload.com/videos/twins-one-guitar-5122ed655a1cb35c41003c64',
+        _SELFTESTTITLE => 'Twins one guitar',
+        PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*sevenload\.com/videos/.+-([[:alnum:]]+))'],
         @_,
     );
 
@@ -32,7 +33,7 @@ sub _parse {
     my $pattern = shift;
     my $content;
     my $metadata = {};
-    my $p = XML::Simple->new();
+    my $p;
     my $t;
 
     $url =~ m|$pattern|;
@@ -45,24 +46,35 @@ sub _parse {
     $metadata->{'TITLE'} = undef;
     $metadata->{'DLURL'} = undef;
 
+    # Get the HTML page for the title
+    unless(defined($content = $self->simple_get($url))) {
+        $self->error('Could not download HTM');
+        return undef;
+    }
+
+    $p = HTML::TokeParser->new(\$content);
+    while ($t = $p->get_tag('meta')) {
+        if ('meta' eq $t->[0]) {
+            if (exists($t->[1]->{'property'}) and ($t->[1]->{'property'} eq 'og:title')) {
+                $metadata->{'TITLE'} = $t->[1]->{'content'};
+            }
+        }
+    }
+
     # Get the XML file containing the video metadata
-    unless(defined($content = $self->simple_get(sprintf('http://flash.sevenload.com/player?itemId=%s', $2)))) {
+    unless(defined($content = $self->simple_get(sprintf('http://player-services.sevenload.com/p/1/sp/1/playManifest/entryId/%s', $2)))) {
         $self->error('Could not download XML metadata');
         return undef;
     }
 
+    $p = XML::Simple->new();
     unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
         $self->error('Could not parse XML metadata');
         return undef;
     }
 
     # Loop through the video streams
-    foreach(@{$t->{'playerconfig'}->{'playlists'}->{'playlist'}->{'items'}->{'item'}->{'videos'}->{'video'}->{'streams'}->{'stream'}}) {
-        if ($_->{'quality'} eq 'high') {
-            $metadata->{'DLURL'} = $_->{'locations'}->{'location'}->{'content'};
-        }
-    }
-    $metadata->{'TITLE'} = $t->{'playerconfig'}->{'playlists'}->{'playlist'}->{'items'}->{'item'}->{'title'};
+    $metadata->{'DLURL'} = $t->{'manifest'}->{'media'}->{'url'};
 
     unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
         $self->error('Could not extract download URL and title');