+# Grabber for dailymotion.com
#
-# download strategy revised using
-# http://www.kde-apps.org/content/show.php?content=41456
+# (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
+# licensed under GNU GPL v2
-package DailyMotionGrabber;
+package videosite::DailyMotionGrabber;
-use GrabberBase;
-@ISA = qw(GrabberBase);
+use videosite::GrabberBase;
+@ISA = qw(videosite::GrabberBase);
use LWP::Simple qw(!get);
use HTML::Parser;
+use videosite::JSArrayParser;
use Data::Dumper;
use strict;
my $class = shift;
my $self = $class->SUPER::new();
- $self->{'NAME'} = 'youtube';
- $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*.dailymotion.com/(?:[^/]+/)*video/([-a-zA-Z0-9_]+)'];
+ $self->{'NAME'} = 'dailymotion';
+ $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*dailymotion.com/(?:[^/]+/)*video/([-a-zA-Z0-9_]+))'];
bless($self, $class);
+ $self->_prepare_parameters();
+
return $self;
}
$metadata->{'URL'} = $url;
$metadata->{'ID'} = $2;
$metadata->{'TYPE'} = 'video';
- $metadata->{'SOURCE'} = 'dailymotion';
+ $metadata->{'SOURCE'} = $self->{'NAME'};
$metadata->{'TITLE'} = undef;
$metadata->{'DLURL'} = undef;
if ('meta' eq $e->[0]) {
if ('title' eq $e->[1]->{'name'}) {
$metadata->{'TITLE'} = $e->[1]->{'content'};
+ $metadata->{'TITLE'} =~ s/^Dailymotion\s+-\s+//;
+ $metadata->{'TITLE'} =~ s/(?:\s+-\s+.*)?$//;
}
}
}
# Look for the download URL
foreach $e (@text) {
- if ($e->[0] =~ m|\.add_variable("url", "([^\"]+)")|) {
- $metadata->{'DLURL'} = $1;
+ if ($e->[0] =~ m|\.addVariable\("sequence",\s*"([^\"]+)"|) {
+ my $sequence = $1;
+ my $jsp = videosite::JSArrayParser->new();
+ my $main;
+ my $s;
+
+ $sequence =~ s/%(..)/chr(hex($1))/ge;
+ $self->debug("Found sequence: %s", $sequence);
+
+ $self->debug("Using %s to parse", ref($jsp));
+ $sequence = $jsp->parse($sequence);
+ $self->debug(Dumper($sequence));
+
+ unless(defined($sequence)) {
+ $self->error("Found sequence, but could not parse");
+ return undef;
+ } else {
+ $self->debug("Parsed sequence: %s", Dumper($sequence));
+
+ foreach (@{$sequence}) {
+ if (exists($_->{'name'}) && ($_->{'name'} eq 'main')) {
+ # Found main section
+ $main = $_->{'layerList'};
+ }
+ }
+ unless(defined($main)) {
+ $self->error("Could not find layerList[main]");
+ return undef;
+ }
+
+ foreach (@{$main}) {
+ if (exists($_->{'name'}) && ($_->{'name'} eq 'video')) {
+ # Found video section
+ if (exists($_->{'param'}->{'hdURL'})) {
+ $metadata->{'DLURL'} = $_->{'param'}->{'hdURL'};
+ } elsif (exists($_->{'param'}->{'hqURL'})) {
+ $metadata->{'DLURL'} = $_->{'param'}->{'hqURL'};
+ } elsif (exists($_->{'param'}->{'hqURL'})) {
+ $metadata->{'DLURL'} = $_->{'param'}->{'sdURL'};
+ } else {
+ $self->error("Video section found, but no URLs");
+ return undef;
+ }
+ }
+ }
+ }
}
}