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 _SELFTESTURL => 'http://www.dailymotion.com/video/xylv6u_moon-duo-sleepwalker_music',
22 _SELFTESTTITLE => 'Moon Duo - Sleepwalker',
23 PATTERNS => ['(http://(?:[-a-zA-Z0-9_.]+\.)*dailymotion.com/(?:[^/]+/)*video/([-a-zA-Z0-9_]+))'],
27 return bless($self, $class);
44 $metadata->{'URL'} = $url;
45 $metadata->{'ID'} = $2;
46 $metadata->{'TYPE'} = 'video';
47 $metadata->{'SOURCE'} = $self->{'NAME'};
48 $metadata->{'TITLE'} = undef;
49 $metadata->{'DLURL'} = undef;
51 unless(defined($content = $self->simple_get(sprintf('http://www.dailymotion.com/video/%s', $2)))) {
52 $self->error('Could not download %s', $url);
56 $p = HTML::TokeParser->new(\$content);
58 # Look for the title in the meta tags
59 while ($e = $p->get_tag('meta', 'script')) {
60 if ('meta' eq $e->[0]) {
61 if (exists($e->[1]->{'property'}) && ('og:title' eq $e->[1]->{'property'})) {
62 $metadata->{'TITLE'} = $e->[1]->{'content'};
64 } elsif ('script' eq $e->[0]) {
65 my $c = $p->get_text();
67 $self->debug("Found script: %s", $c);
69 if ($c =~ m|flashvars = (.+);$|m) {
71 my $jsp = videosite::JSArrayParser->new();
76 $self->debug("Found flashvars: %s", $flashvars);
78 $self->debug("Using %s to parse", ref($jsp));
79 $flashvars = $jsp->parse($flashvars);
80 $self->debug("Parsed flashvars: %s", Dumper($flashvars));
82 $sequence = $flashvars->{'sequence'};
83 $sequence =~ s/%(..)/chr(hex($1))/ge;
85 $self->debug("Decoded sequence: %s", $sequence);
86 $sequence = $jsp->parse($sequence);
88 unless(defined($sequence)) {
89 $self->error("Found sequence, but could not parse");
92 $self->debug("Parsed sequence: %s", Dumper($sequence));
94 $l = $self->_fetch_layer($sequence->{'sequence'}, "root/layerList", "background/sequenceList", "main/layerList", "video/param");
96 $self->error("Could not find video layer");
100 # Found video section
101 if (exists($l->{'hd1080URL'})) {
102 $metadata->{'DLURL'} = $l->{'hd1080URL'};
103 } elsif (exists($l->{'hd720URL'})) {
104 $metadata->{'DLURL'} = $l->{'hd720URL'};
105 } elsif (exists($l->{'hqURL'})) {
106 $metadata->{'DLURL'} = $l->{'hqURL'};
107 } elsif (exists($l->{'sdURL'})) {
108 $metadata->{'DLURL'} = $l->{'sdURL'};
109 } elsif (exists($l->{'ldURL'})) {
110 $metadata->{'DLURL'} = $l->{'ldURL'};
112 $self->error("Video section found, but no URLs");
120 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
121 $self->error('Could not determine download URL');
130 my $sequence = shift;
136 $self->debug("Looking for %s in %s", $point, Dumper($sequence));
138 unless(defined($point)) {
139 $self->debug("Reached last point");
142 ($point, $next) = split(/\//, $point, 2);
144 foreach (@{$sequence}) {
145 if (exists($_->{'name'}) and ($_->{'name'} eq $point)) {
146 if (exists($_->{$next})) {
147 $self->debug("Using %s in %s", $next, $point);
148 return $self->_fetch_layer($_->{$next}, @points);
150 $self->debug("%s found, but no %s", $point, $next);
157 $self->debug("Could not find entry named %s", $point);