« Simple query_string based http accelerator for a dynamic web page | Main | LED Clear Lenses for my Mazda 3 »

juin 10, 2006

Fun with perl and Google Video

A couple weeks ago, I started playing with Google Video, it's a great ressource, I really love it. The only thing that bugs me with this tool is that you can't download the video to your hard drive. You can download a Google Video Player (GVP) file that's effectively a pointer to the video, but you can't download the actual MPG or AVI.

Well, I recently found out that you could. So I modified a perl module to make it very easy to do!

CPAN has a perl module called WWW::Google::Video. However, it seems that the module was made before Google decided to put a GVP file for download. So I extendted the module to support the GVP file.

I sent my modified version to the author (莉洛) but until it makes its way into CPAN, I'll keep a local copy for your downloading pleasure.

I also added a demo CGI in the documentation, you should check it out.

Here's the source code for the demo:

#!/usr/bin/perl -T

use strict;
use warnings "all";
use WWW::Google::Video;
use CGI qw/:standard/;

print header;

if (param()) {
  die "Not a Google Video URL." unless param('url') =~ m#\Qhttp://video.google.com/videoplay?\E#;
  my $vid=new WWW::Google::Video;
  $vid->fetch(param('url'));

  print start_html('Fun with perl and with Google Video: '.$vid->{title}),"\n";
  print h1('Fun with perl and Google Video: '.$vid->{title}),"\n";
  print p,$vid->{description},p,"\n";
  print p,"[ ",a({href=>'http://video.google.com/videoplay?docid='.$vid->{docid}},"See on Google Video")," | ";
  print a({href=>$vid->{avi}},"Download as DivX AVI")," ]",p,"\n";
  print p,"You will need the ",a({href=>'http://divx.com/'},"DivX Player")," in order to play the downloaded AVI.",p,"\n";

  foreach(@{ $vid->{pic} }){
    print img({src=>$_}),"\n";
  }
} else {
  print start_html('Fun with perl and Google Video'),"\n";
  print h1('Fun with perl and Google Video'),"\n";
}

print start_form('get'),"\n";
print "Enter the Google Video URL that you want to play:",p,textfield('url','',65),p,"\n";
print submit,"\n",end_form,"\n";

print end_html,"\n";

Posted by gfk at juin 10, 2006 10:09 AM

Comments

Post a comment

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?