# (c) 2007 by Ralf Ertzinger # licensed under GNU GPL v2 # # Grabber for video.google.com package videosite::GoogleGrabber; use videosite::GrabberBase; @ISA = qw(videosite::GrabberBase); use HTML::TokeParser; use Data::Dumper; use strict; sub new { my $class = shift; my $self = $class->SUPER::new( NAME => 'google', PATTERNS => ['(http://video\.google\.com/videoplay\?docid=([-\d]+))'], _PARAMS => { QUALITY => ['normal', 'Quality of the video to download. normal = standard resolution flash video, h264 = high resolution MPEG4 video'] }, @_, ); return bless($self, $class); } sub _parse { my $self = shift; my $url = shift; my $pattern = shift; my $content; my $metadata = {}; my $p; my $e; my $quality = $self->_getval('QUALITY'); $url =~ m|$pattern|; $url = $1; $metadata->{'URL'} = $url; $metadata->{'ID'} = $2; $metadata->{'TYPE'} = 'video'; $metadata->{'SOURCE'} = $self->{'NAME'}; $metadata->{'TITLE'} = undef; $metadata->{'DLURL'} = undef; unless(defined($content = $self->simple_get(sprintf('http://video.google.com/videohosted?docid=%s', $2)))) { $self->error('Could not download %s', $url); return undef; } $p = HTML::TokeParser->new(\$content); # Look for the title if ($p->get_tag('title')) { $metadata->{'TITLE'} = $p->get_text(); $metadata->{'TITLE'} =~ s/\s?- Google Video$//s; } if ($quality eq 'h264') { while ($e = $p->get_tag('a')) { if ((exists($e->[1]{'id'})) and ('ipoddownloadlink' eq $e->[1]{'id'})) { $metadata->{'DLURL'} = $e->[1]{'href'}; last; } } } else { while ($e = $p->get_tag('script')) { if ($p->get_text() =~ m|googleplayer\.swf\?\\46videoUrl\\75(.+?)\\46|s) { my $u = $1; $u =~ s/%(..)/chr(hex($1))/ge; $metadata->{'DLURL'} = $u; last; } } } unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) { $self->error('Could not determine download URL'); return undef; } return $metadata; } 1;