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']
27 return bless($self, $class);
38 my $quality = $self->_getval('QUALITY');
43 $metadata->{'URL'} = $url;
44 $metadata->{'ID'} = $2;
45 $metadata->{'TYPE'} = 'video';
46 $metadata->{'SOURCE'} = $self->{'NAME'};
47 $metadata->{'TITLE'} = undef;
48 $metadata->{'DLURL'} = undef;
50 unless(defined($content = $self->simple_get(sprintf('http://video.google.com/videohosted?docid=%s', $2)))) {
51 $self->error('Could not download %s', $url);
55 $p = HTML::TokeParser->new(\$content);
58 if ($p->get_tag('title')) {
59 $metadata->{'TITLE'} = $p->get_text();
60 $metadata->{'TITLE'} =~ s/\s?- Google Video$//s;
63 if ($quality eq 'h264') {
64 while ($e = $p->get_tag('a')) {
65 if ((exists($e->[1]{'id'})) and ('ipoddownloadlink' eq $e->[1]{'id'})) {
66 $metadata->{'DLURL'} = $e->[1]{'href'};
71 while ($e = $p->get_tag('script')) {
72 if ($p->get_text() =~ m|googleplayer\.swf\?\\46videoUrl\\75(.+?)\\46|s) {
74 $u =~ s/%(..)/chr(hex($1))/ge;
75 $metadata->{'DLURL'} = $u;
81 unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
82 $self->error('Could not determine download URL');