1 # (c) 2007 by Ralf Ertzinger <ralf@camperquake.de>
2 # licensed under GNU GPL v2
4 # Grabber for video.google.com
6 package videosite::GoogleGrabber;
8 use videosite::GrabberBase;
9 @ISA = qw(videosite::GrabberBase);
18 my $self = $class->SUPER::new(
20 PATTERNS => ['(http://video\.google\.com/videoplay\?docid=([-\d]+))'],
22 QUALITY => ['normal', 'Quality of the video to download. normal = standard resolution flash video, h264 = high resolution MPEG4 video']
26 return bless($self, $class);
37 my $quality = $self->_getval('QUALITY');
42 $metadata->{'URL'} = $url;
43 $metadata->{'ID'} = $2;
44 $metadata->{'TYPE'} = 'video';
45 $metadata->{'SOURCE'} = $self->{'NAME'};
46 $metadata->{'TITLE'} = undef;
47 $metadata->{'DLURL'} = undef;
49 unless(defined($content = $self->simple_get(sprintf('http://video.google.com/videohosted?docid=%s', $2)))) {
50 $self->error('Could not download %s', $url);
54 $p = HTML::TokeParser->new(\$content);
57 if ($p->get_tag('title')) {
58 $metadata->{'TITLE'} = $p->get_text();
59 $metadata->{'TITLE'} =~ s/\s?- Google Video$//s;
62 if ($quality eq 'h264') {
63 while ($e = $p->get_tag('a')) {
64 if ((exists($e->[1]{'id'})) and ('ipoddownloadlink' eq $e->[1]{'id'})) {
65 $metadata->{'DLURL'} = $e->[1]{'href'};
70 while ($e = $p->get_tag('script')) {
71 if ($p->get_text() =~ m|googleplayer\.swf\?\\46videoUrl\\75(.+?)\\46|s) {
73 $u =~ s/%(..)/chr(hex($1))/ge;
74 $metadata->{'DLURL'} = $u;
80 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
81 $self->error('Could not determine download URL');