Shane Vitarana more brain > blog.html

[ANN] YouTube Library 0.8.0 Released


RubyForge project page:

My little YouTube Library has finally reached version 0.8.0, thanks to a sizable patch by Walter Korman, and some functional programming tips by Lucas Carlson. It now includes full unit tests, which can be run using rake, and all classes are under the YouTube namespace. Please note that this version breaks backwards compatibility. If you want to upgrade or install, do gem install youtube. You can still get the old version with gem install youtube --version 0.1.1.


All classes are under the YouTube namespace. To create a new YouTube client, you now have to do: youtube = 'DEVELOPER ID'

Object Mapping

Results from YouTube are converted to corresponding Ruby objects. For example, video.view\_count will return an Integer, and video.rating\_avg will return a Float.

Embed HTML

Everyone wants to use this to embed videos on their Web3.1 site, no? Walter added the method embed\_html which takes in a width and height (or uses the default values) and outputs all the HTML you need to embed the Flash video on your site. Therefore, in a Rails view, you can do something like: <%= video.embed\_html %>

Unit Tests

Run unit tests with % rake test. This allows for easy detection if YouTube ever changes their API on us.

Video Details

I got a lot of questions after the first release about how to get video details, so here in an example:

video = featured_videos.first       # returns a YouTube::Video object
details = video_details(   # returns a YouTube::VideoDetails object
@tags = details.tags                # returns a String for all tags for this video

In a similar vein to this library, Walter has released a Google Video API for Ruby that brilliantly uses Hpricot to parse video meta-data.