Google Video

A Ruby object-oriented interface to the video content available on Google Video at video.google.com. Functionality is provided to do things including:

  • retrieve a list of current top videos (see GoogleVideo::Client#top_videos)

  • search for a list of videos matching a set of search query parameters (see GoogleVideo::Client#video_search)

  • retrieve full detailed information on a specific video (see GoogleVideo::Client#video_details)

The RubyForge project is at rubyforge.org/projects/google-video.

About

As the Google Video web site has no formally exposed API, we make use of the lovely Hpricot to parse desired data from the Google Video web pages.

The Google Video web site is still in beta, so it is likely to change in ways that could impact the proper functionality of this library. There is an initial set of unit tests provided with this library which should give some guidance as to its proper operation, and we will endeavor to update the library in accordance with Google’s changes, but no promises can be made, so none can be broken, and hence your mileage may vary.

See also the YouTube library for Ruby library access to another popular Google-owned video site. Will these two one day live together in harmonious glory? Will intrepid Google engineers rewrite YouTube to make use of GFS, Bigtable and a variety of Googley AJAX love? Only time will tell!

Installing

We recommend installing google-video via rubygems (see also www.rubygems.org).

Once you have rubygems installed on your system, you can easily install the google-video gem by executing:

% gem install --include-dependencies google-video

google-video requires the Hpricot library for parsing HTML, and the HTMLEntities library for, uh, decoding HTML entities. Both will be auto-installed by the above command if not already present.

Usage

Instantiate a GoogleVideo::Client and use its methods (e.g. GoogleVideo::Client#top_videos, GoogleVideo::Client#video_search) to make requests of the Google Video server.

Each Client method takes as a parameter its respective request object (e.g. GoogleVideo::VideoSearchRequest) and returns its respective response object (e.g. GoogleVideo::VideoSearchResponse). See method documentation for links and more information

An example program showing some simple requests follows. The script is available in the distribution under examples/example.rb along with several others.

#!/usr/bin/env ruby

require 'rubygems'
require 'google-video'
require 'pp'

# create a client with which to submit requests
client = GoogleVideo::Client.new

# look up a list of the top 100 videos
request = GoogleVideo::TopVideosRequest.new
response = client.top_videos request
print "Top 5 Videos:\n"
response.videos[0...5].each { |video| pp(video) }

# choose one at random to look up in detail
index = rand(response.videos.length)
video = response.videos[index].video
print "\nRequesting video detail for:\n"
pp(video)

# look up the video's details
request = GoogleVideo::VideoDetailsRequest.new :video => video
response = client.video_details request
print "\nDetail:\n"
pp(response)

# look up a previously identified video by its document id
previous_doc_id = 8718762874044429036
request = GoogleVideo::VideoDetailsRequest.new :doc_id => previous_doc_id
response = client.video_details request
print "\nDetail on doc id #{previous_doc_id}:\n"
pp(response)

# search for a video on turtles
query = 'turtles'
request = GoogleVideo::VideoSearchRequest.new :query => query
response = client.video_search request
print "\nResults of video search for #{query}:\n"
pp(response)

License

This library is provided via the GNU LGPL license at www.gnu.org/licenses/lgpl.html.

Authors

Copyright 2006, Walter Korman <[email protected]>, www.lemurware.com.