2 # download strategy revised using
3 # http://www.kde-apps.org/content/show.php?content=41456
5 package DailyMotionGrabber;
8 @ISA = qw(GrabberBase);
10 use LWP::Simple qw(!get);
18 my $self = $class->SUPER::new();
20 $self->{'NAME'} = 'youtube';
21 $self->{'PATTERNS'} = ['(http://(?:[-a-zA-Z0-9_.]+\.)*.dailymotion.com/(?:[^/]+/)*video/([-a-zA-Z0-9_]+)'];
34 my $p = HTML::Parser->new(api_version => 3);
42 $metadata->{'URL'} = $url;
43 $metadata->{'ID'} = $2;
44 $metadata->{'TYPE'} = 'video';
45 $metadata->{'SOURCE'} = 'dailymotion';
46 $metadata->{'TITLE'} = undef;
47 $metadata->{'DLURL'} = undef;
49 unless(defined($content = LWP::Simple::get(sprintf('http://www.dailymotion.com/video/%s', $2)))) {
50 $self->error('Could not download %s', $url);
54 $p->handler(start => \@accum, "tagname, attr");
55 $p->handler(text => \@text, "text");
56 $p->report_tags(qw(meta script));
60 # Look for the title in the meta tags
62 if ('meta' eq $e->[0]) {
63 if ('title' eq $e->[1]->{'name'}) {
64 $metadata->{'TITLE'} = $e->[1]->{'content'};
69 # Look for the download URL
71 if ($e->[0] =~ m|\.add_variable("url", "([^\"]+)")|) {
72 $metadata->{'DLURL'} = $1;
76 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
77 $self->error('Could not determine download URL');