1 # Grabber for dailymotion.com
3 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
4 # licensed under GNU GPL v2
6 package DailyMotionGrabber;
9 @ISA = qw(GrabberBase);
11 use LWP::Simple qw(!get);
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_]+))'];
35 my $p = HTML::Parser->new(api_version => 3);
43 $metadata->{'URL'} = $url;
44 $metadata->{'ID'} = $2;
45 $metadata->{'TYPE'} = 'video';
46 $metadata->{'SOURCE'} = 'dailymotion';
47 $metadata->{'TITLE'} = undef;
48 $metadata->{'DLURL'} = undef;
50 unless(defined($content = LWP::Simple::get(sprintf('http://www.dailymotion.com/video/%s', $2)))) {
51 $self->error('Could not download %s', $url);
55 $p->handler(start => \@accum, "tagname, attr");
56 $p->handler(text => \@text, "text");
57 $p->report_tags(qw(meta script));
61 # Look for the title in the meta tags
63 if ('meta' eq $e->[0]) {
64 if ('title' eq $e->[1]->{'name'}) {
65 $metadata->{'TITLE'} = $e->[1]->{'content'};
66 $metadata->{'TITLE'} =~ s/^Dailymotion\s*:\s*//;
71 # Look for the download URL
73 if ($e->[0] =~ m|\.addVariable\("url", "([^\"]+)"|) {
74 $metadata->{'DLURL'} = $1;
75 $metadata->{'DLURL'} =~ s/%(..)/chr(hex($1))/ge;
80 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
81 $self->error('Could not determine download URL');