Shane Vitarana more brain > blog.html

[ANN] YouTube Library 0.8.0 Released

Documentation: http://youtube.shanesbrain.net/

RubyForge project page: http://rubyforge.org/projects/youtube/

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.

Namespace

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

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: <typo:code><%= video.embed_html %></typo:code>

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(video.id)   # 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.