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->{_SELFTESTURL} = 'http://www.dailymotion.com/video/xylv6u_moon-duo-sleepwalker_music';
23 $self->{_SELFTESTTITLE} = 'Moon Duo - Sleepwalker';
24 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*dailymotion.com/(?:[^/]+/)*video/([-a-zA-Z0-9_]+))'];
28 $self->_prepare_parameters();
47 $metadata->{'URL'} = $url;
48 $metadata->{'ID'} = $2;
49 $metadata->{'TYPE'} = 'video';
50 $metadata->{'SOURCE'} = $self->{'NAME'};
51 $metadata->{'TITLE'} = undef;
52 $metadata->{'DLURL'} = undef;
54 unless(defined($content = $self->simple_get(sprintf('http://www.dailymotion.com/video/%s', $2)))) {
55 $self->error('Could not download %s', $url);
59 $p = HTML::TokeParser->new(\$content);
61 # Look for the title in the meta tags
62 while ($e = $p->get_tag('meta', 'script')) {
63 if ('meta' eq $e->[0]) {
64 if (exists($e->[1]->{'property'}) && ('og:title' eq $e->[1]->{'property'})) {
65 $metadata->{'TITLE'} = $e->[1]->{'content'};
67 } elsif ('script' eq $e->[0]) {
68 my $c = $p->get_text();
70 $self->debug("Found script: %s", $c);
72 if ($c =~ m|flashvars = (.+);$|m) {
74 my $jsp = videosite::JSArrayParser->new();
79 $self->debug("Found flashvars: %s", $flashvars);
81 $self->debug("Using %s to parse", ref($jsp));
82 $flashvars = $jsp->parse($flashvars);
83 $self->debug("Parsed flashvars: %s", Dumper($flashvars));
85 $sequence = $flashvars->{'sequence'};
86 $sequence =~ s/%(..)/chr(hex($1))/ge;
88 $self->debug("Decoded sequence: %s", $sequence);
89 $sequence = $jsp->parse($sequence);
91 unless(defined($sequence)) {
92 $self->error("Found sequence, but could not parse");
95 $self->debug("Parsed sequence: %s", Dumper($sequence));
97 $l = $self->_fetch_layer($sequence->{'sequence'}, "root/layerList", "background/sequenceList", "main/layerList", "video/param");
99 $self->error("Could not find video layer");
103 # Found video section
104 if (exists($l->{'hd1080URL'})) {
105 $metadata->{'DLURL'} = $l->{'hd1080URL'};
106 } elsif (exists($l->{'hd720URL'})) {
107 $metadata->{'DLURL'} = $l->{'hd720URL'};
108 } elsif (exists($l->{'hqURL'})) {
109 $metadata->{'DLURL'} = $l->{'hqURL'};
110 } elsif (exists($l->{'sdURL'})) {
111 $metadata->{'DLURL'} = $l->{'sdURL'};
112 } elsif (exists($l->{'ldURL'})) {
113 $metadata->{'DLURL'} = $l->{'ldURL'};
115 $self->error("Video section found, but no URLs");
123 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
124 $self->error('Could not determine download URL');
133 my $sequence = shift;
139 $self->debug("Looking for %s in %s", $point, Dumper($sequence));
141 unless(defined($point)) {
142 $self->debug("Reached last point");
145 ($point, $next) = split(/\//, $point, 2);
147 foreach (@{$sequence}) {
148 if (exists($_->{'name'}) and ($_->{'name'} eq $point)) {
149 if (exists($_->{$next})) {
150 $self->debug("Using %s in %s", $next, $point);
151 return $self->_fetch_layer($_->{$next}, @points);
153 $self->debug("%s found, but no %s", $point, $next);
160 $self->debug("Could not find entry named %s", $point);