1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
4 # Grabber for video.google.com
9 @ISA = qw(GrabberBase);
11 use LWP::Simple qw(!get);
19 my $self = $class->SUPER::new();
21 $self->{'NAME'} = 'google';
22 $self->{'PATTERNS'} = ['(http://video\.google\.com/videoplay\?docid=([-\d]+))'];
25 $self->_prepare_parameters();
36 my $p = HTML::Parser->new(api_version => 3);
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 = LWP::Simple::get(sprintf('http://video.google.com/videoplay?docid=%s', $2)))) {
52 $self->error('Could not download %s', $url);
56 $p->handler(start => \@accum, "tagname, attr");
57 $p->handler(text => \@text, "text");
58 $p->report_tags(qw(embed div));
62 # Look for the title in the div tags
64 if ('div' eq $e->[0]) {
65 if ((exists($e->[1]->{'class'})) and ('title' eq $e->[1]->{'class'})) {
66 $metadata->{'TITLE'} = $e->[1]->{'title'};
70 if ('embed' eq $e->[0]) {
71 if ((exists($e->[1]->{'src'})) and ($e->[1]->{'src'} =~ m|^/googleplayer.swf\?\&videoUrl=([^&]+)\&|)) {
72 $metadata->{'DLURL'} = $1;
73 $metadata->{'DLURL'} =~ s/%(..)/chr(hex($1))/ge;
78 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
79 $self->error('Could not determine download URL');