1 # Grabber for dailymotion.com
3 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
4 # licensed under GNU GPL v2
6 package videosite::DailyMotionGrabber;
8 use videosite::GrabberBase;
9 @ISA = qw(videosite::GrabberBase);
11 use LWP::Simple qw(!get);
13 use videosite::JSArrayParser;
20 my $self = $class->SUPER::new();
22 $self->{'NAME'} = 'dailymotion';
23 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*dailymotion.com/(?:[^/]+/)*video/([-a-zA-Z0-9_]+))'];
27 $self->_prepare_parameters();
38 my $p = HTML::Parser->new(api_version => 3);
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 unless(defined($content = LWP::Simple::get(sprintf('http://www.dailymotion.com/video/%s', $2)))) {
54 $self->error('Could not download %s', $url);
58 $p->handler(start => \@accum, "tagname, attr");
59 $p->handler(text => \@text, "text");
60 $p->report_tags(qw(meta script));
64 # Look for the title in the meta tags
66 if ('meta' eq $e->[0]) {
67 if ('title' eq $e->[1]->{'name'}) {
68 $metadata->{'TITLE'} = $e->[1]->{'content'};
69 $metadata->{'TITLE'} =~ s/^Dailymotion\s+-\s+//;
70 $metadata->{'TITLE'} =~ s/(?:\s+-\s+.*)?$//;
75 # Look for the download URL
77 if ($e->[0] =~ m|\.addVariable\("sequence",\s*"([^\"]+)"|) {
79 my $jsp = videosite::JSArrayParser->new();
83 $sequence =~ s/%(..)/chr(hex($1))/ge;
84 $self->debug("Found sequence: %s", $sequence);
86 $self->debug("Using %s to parse", ref($jsp));
87 $sequence = $jsp->parse($sequence);
88 $self->debug(Dumper($sequence));
90 unless(defined($sequence)) {
91 $self->error("Found sequence, but could not parse");
94 $self->debug("Parsed sequence: %s", Dumper($sequence));
96 $l = $self->_fetch_layer($sequence, "root/layerList", "background/sequenceList", "main/layerList", "video/param");
98 $self->error("Could not find video layer");
102 # Found video section
103 if (exists($l->{'videoPluginParameters'}->{'hdURL'})) {
104 $metadata->{'DLURL'} = $l->{'videoPluginParameters'}->{'hdURL'};
105 } elsif (exists($l->{'videoPluginParameters'}->{'hqURL'})) {
106 $metadata->{'DLURL'} = $l->{'videoPluginParameters'}->{'hqURL'};
107 } elsif (exists($l->{'videoPluginParameters'}->{'hqURL'})) {
108 $metadata->{'DLURL'} = $l->{'videoPluginParameters'}->{'sdURL'};
110 $self->error("Video section found, but no URLs");
117 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
118 $self->error('Could not determine download URL');
127 my $sequence = shift;
133 $self->debug("Looking for %s in %s", $point, Dumper($sequence));
135 unless(defined($point)) {
136 $self->debug("Reached last point");
139 ($point, $next) = split(/\//, $point, 2);
141 foreach (@{$sequence}) {
142 if (exists($_->{'name'}) and ($_->{'name'} eq $point)) {
143 if (exists($_->{$next})) {
144 $self->debug("Using %s in %s", $next, $point);
145 return $self->_fetch_layer($_->{$next}, @points);
147 $self->debug("%s found, but no %s", $point, $next);
154 $self->debug("Could not find entry named %s", $point);