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 foreach (@{$sequence}) {
97 if (exists($_->{'name'}) && ($_->{'name'} eq 'main')) {
99 $main = $_->{'layerList'};
102 unless(defined($main)) {
103 $self->error("Could not find layerList[main]");
108 if (exists($_->{'name'}) && ($_->{'name'} eq 'video')) {
109 # Found video section
110 if (exists($_->{'param'}->{'hdURL'})) {
111 $metadata->{'DLURL'} = $_->{'param'}->{'hdURL'};
112 } elsif (exists($_->{'param'}->{'hqURL'})) {
113 $metadata->{'DLURL'} = $_->{'param'}->{'hqURL'};
114 } elsif (exists($_->{'param'}->{'hqURL'})) {
115 $metadata->{'DLURL'} = $_->{'param'}->{'sdURL'};
117 $self->error("Video section found, but no URLs");
126 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
127 $self->error('Could not determine download URL');