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);
12 use videosite::JSArrayParser;
19 my $self = $class->SUPER::new(
20 NAME => 'dailymotion',
21 PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*dailymotion.com/(?:[^/]+/)*video/([-a-zA-Z0-9_]+))'],
25 return bless($self, $class);
34 my $p = HTML::Parser->new(api_version => 3);
42 $metadata->{'URL'} = $url;
43 $metadata->{'ID'} = $2;
44 $metadata->{'TYPE'} = 'video';
45 $metadata->{'SOURCE'} = $self->{'NAME'};
46 $metadata->{'TITLE'} = undef;
47 $metadata->{'DLURL'} = undef;
49 unless(defined($content = $self->simple_get(sprintf('http://www.dailymotion.com/video/%s', $2)))) {
50 $self->error('Could not download %s', $url);
54 $p->handler(start => \@accum, "tagname, attr");
55 $p->handler(text => \@text, "text");
56 $p->report_tags(qw(meta script));
60 # Look for the title in the meta tags
62 if ('meta' eq $e->[0]) {
63 if ('title' eq $e->[1]->{'name'}) {
64 $metadata->{'TITLE'} = $e->[1]->{'content'};
65 $metadata->{'TITLE'} =~ s/^Dailymotion\s+-\s+//;
66 $metadata->{'TITLE'} =~ s/(?:\s+-\s+.*)?$//;
71 # Look for the download URL
73 if ($e->[0] =~ m|\.addVariable\("sequence",\s*"([^\"]+)"|) {
75 my $jsp = videosite::JSArrayParser->new();
79 $sequence =~ s/%(..)/chr(hex($1))/ge;
80 $self->debug("Found sequence: %s", $sequence);
82 $self->debug("Using %s to parse", ref($jsp));
83 $sequence = $jsp->parse($sequence);
84 $self->debug(Dumper($sequence));
86 unless(defined($sequence)) {
87 $self->error("Found sequence, but could not parse");
90 $self->debug("Parsed sequence: %s", Dumper($sequence));
92 $l = $self->_fetch_layer($sequence, "root/layerList", "background/sequenceList", "main/layerList", "video/param");
94 $self->error("Could not find video layer");
99 if (exists($l->{'videoPluginParameters'}->{'hdURL'})) {
100 $metadata->{'DLURL'} = $l->{'videoPluginParameters'}->{'hdURL'};
101 } elsif (exists($l->{'videoPluginParameters'}->{'hqURL'})) {
102 $metadata->{'DLURL'} = $l->{'videoPluginParameters'}->{'hqURL'};
103 } elsif (exists($l->{'videoPluginParameters'}->{'hqURL'})) {
104 $metadata->{'DLURL'} = $l->{'videoPluginParameters'}->{'sdURL'};
106 $self->error("Video section found, but no URLs");
113 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
114 $self->error('Could not determine download URL');
123 my $sequence = shift;
129 $self->debug("Looking for %s in %s", $point, Dumper($sequence));
131 unless(defined($point)) {
132 $self->debug("Reached last point");
135 ($point, $next) = split(/\//, $point, 2);
137 foreach (@{$sequence}) {
138 if (exists($_->{'name'}) and ($_->{'name'} eq $point)) {
139 if (exists($_->{$next})) {
140 $self->debug("Using %s in %s", $next, $point);
141 return $self->_fetch_layer($_->{$next}, @points);
143 $self->debug("%s found, but no %s", $point, $next);
150 $self->debug("Could not find entry named %s", $point);