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();
21 $self->{'NAME'} = 'dailymotion';
22 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*dailymotion.com/(?:[^/]+/)*video/([-a-zA-Z0-9_]+))'];
26 $self->_prepare_parameters();
37 my $p = HTML::Parser->new(api_version => 3);
45 $metadata->{'URL'} = $url;
46 $metadata->{'ID'} = $2;
47 $metadata->{'TYPE'} = 'video';
48 $metadata->{'SOURCE'} = $self->{'NAME'};
49 $metadata->{'TITLE'} = undef;
50 $metadata->{'DLURL'} = undef;
52 unless(defined($content = $self->simple_get(sprintf('http://www.dailymotion.com/video/%s', $2)))) {
53 $self->error('Could not download %s', $url);
57 $p->handler(start => \@accum, "tagname, attr");
58 $p->handler(text => \@text, "text");
59 $p->report_tags(qw(meta script));
63 # Look for the title in the meta tags
65 if ('meta' eq $e->[0]) {
66 if ('title' eq $e->[1]->{'name'}) {
67 $metadata->{'TITLE'} = $e->[1]->{'content'};
68 $metadata->{'TITLE'} =~ s/^Dailymotion\s+-\s+//;
69 $metadata->{'TITLE'} =~ s/(?:\s+-\s+.*)?$//;
74 # Look for the download URL
76 if ($e->[0] =~ m|\.addVariable\("sequence",\s*"([^\"]+)"|) {
78 my $jsp = videosite::JSArrayParser->new();
82 $sequence =~ s/%(..)/chr(hex($1))/ge;
83 $self->debug("Found sequence: %s", $sequence);
85 $self->debug("Using %s to parse", ref($jsp));
86 $sequence = $jsp->parse($sequence);
87 $self->debug(Dumper($sequence));
89 unless(defined($sequence)) {
90 $self->error("Found sequence, but could not parse");
93 $self->debug("Parsed sequence: %s", Dumper($sequence));
95 $l = $self->_fetch_layer($sequence, "root/layerList", "background/sequenceList", "main/layerList", "video/param");
97 $self->error("Could not find video layer");
101 # Found video section
102 if (exists($l->{'videoPluginParameters'}->{'hdURL'})) {
103 $metadata->{'DLURL'} = $l->{'videoPluginParameters'}->{'hdURL'};
104 } elsif (exists($l->{'videoPluginParameters'}->{'hqURL'})) {
105 $metadata->{'DLURL'} = $l->{'videoPluginParameters'}->{'hqURL'};
106 } elsif (exists($l->{'videoPluginParameters'}->{'hqURL'})) {
107 $metadata->{'DLURL'} = $l->{'videoPluginParameters'}->{'sdURL'};
109 $self->error("Video section found, but no URLs");
116 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
117 $self->error('Could not determine download URL');
126 my $sequence = shift;
132 $self->debug("Looking for %s in %s", $point, Dumper($sequence));
134 unless(defined($point)) {
135 $self->debug("Reached last point");
138 ($point, $next) = split(/\//, $point, 2);
140 foreach (@{$sequence}) {
141 if (exists($_->{'name'}) and ($_->{'name'} eq $point)) {
142 if (exists($_->{$next})) {
143 $self->debug("Using %s in %s", $next, $point);
144 return $self->_fetch_layer($_->{$next}, @points);
146 $self->debug("%s found, but no %s", $point, $next);
153 $self->debug("Could not find entry named %s", $point);