1 package DailyMotionGrabber;
4 @ISA = qw(GrabberBase);
6 use LWP::Simple qw(!get);
14 my $self = $class->SUPER::new();
16 $self->{'NAME'} = 'dailymotion';
17 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*dailymotion.com/(?:[^/]+/)*video/([-a-zA-Z0-9_]+))'];
30 my $p = HTML::Parser->new(api_version => 3);
38 $metadata->{'URL'} = $url;
39 $metadata->{'ID'} = $2;
40 $metadata->{'TYPE'} = 'video';
41 $metadata->{'SOURCE'} = 'dailymotion';
42 $metadata->{'TITLE'} = undef;
43 $metadata->{'DLURL'} = undef;
45 unless(defined($content = LWP::Simple::get(sprintf('http://www.dailymotion.com/video/%s', $2)))) {
46 $self->error('Could not download %s', $url);
50 $p->handler(start => \@accum, "tagname, attr");
51 $p->handler(text => \@text, "text");
52 $p->report_tags(qw(meta script));
56 # Look for the title in the meta tags
58 if ('meta' eq $e->[0]) {
59 if ('title' eq $e->[1]->{'name'}) {
60 $metadata->{'TITLE'} = $e->[1]->{'content'};
61 $metadata->{'TITLE'} =~ s/^Dailymotion\s*:\s*//;
66 # Look for the download URL
68 if ($e->[0] =~ m|\.addVariable\("url", "([^\"]+)"|) {
69 $metadata->{'DLURL'} = $1;
70 $metadata->{'DLURL'} =~ s/%(..)/chr(hex($1))/ge;
75 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
76 $self->error('Could not determine download URL');