# (c) 2007 by Ralf Ertzinger # licensed under GNU GPL v2 # # Grabber for sevenload.com/de package videosite::SevenloadGrabber; use videosite::GrabberBase; @ISA = qw(videosite::GrabberBase); use XML::Simple; use HTML::TokeParser; use Data::Dumper; use strict; sub new { my $class = shift; my $self = $class->SUPER::new( NAME => 'sevenload', _SELFTESTURL => 'http://www.sevenload.com/videos/twins-one-guitar-5122ed655a1cb35c41003c64', _SELFTESTTITLE => 'Twins one guitar', PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*sevenload\.com/videos/.+-([[:alnum:]]+))'], @_, ); return bless($self, $class); } sub _parse { my $self = shift; my $url = shift; my $pattern = shift; my $content; my $metadata = {}; my $p; my $t; $url =~ m|$pattern|; $url = $1; $metadata->{'URL'} = $url; $metadata->{'ID'} = $2; $metadata->{'TYPE'} = 'video'; $metadata->{'SOURCE'} = $self->{'NAME'}; $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://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 $metadata->{'DLURL'} = $t->{'manifest'}->{'media'}->{'url'}; unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) { $self->error('Could not extract download URL and title'); return undef; } return $metadata; } 1;