Searching Hulu using C#

9/29/2009

While working on my current project, I needed to be able to search a couple different media websites and use various APIs that are out there. Most of these websites make doing a simple search rather difficult. At best they use something like OAuth/REST but most of them come up with their own system that's just annoying. Then I started looking at Hulu. Hulu, for those of you that have yet to visit, is one of the greatest sites ever. Well assuming you live in the US anyway. It allows you to stream TV, including shows like Spaced which I loved, and movies (although most of the movies are pretty bad). I use it fairly often but never really paid attention to the search feature. It turns out that Hulu didn't really go with a complicated setup for outside apps to search their site. Instead they use RSS feeds and can be searched with a simple URL.

   1: /// <summary>
   2: /// Hulu service helper class
   3: /// </summary>
   4: public static class Hulu
   5: {
   6:     #region Public Static Functions
   7:  
   8:     /// <summary>
   9:     /// Searches hulu for items
  10:     /// </summary>
  11:     /// <param name="SearchTerm">Search term</param>
  12:     /// <returns>An RSS document holding the information</returns>
  13:     public static Document SearchHulu(string SearchTerm)
  14:     {
  15:         Document Results = new Document("http://www.hulu.com/feed/search?query=" + HttpUtility.UrlEncode(SearchTerm) + "&sort_by=relevance");
  16:         return Results;
  17:     }
  18:  
  19:     #endregion
  20: }

The url is simply http://www.hulu.com/feed/search?query=YOURQUERY&sort_by=relevance. That's it. There are other options that you can send in but that URL will give you back your search results in an RSS file. You'll notice that the code above is using a Document class. This is from my RSS feed reader code that can be found either here or in my utility library. However the feeds are pretty much a basic RSS feed, so you can parse it however you would like. There are a couple things to note though. First is that it's using a couple added formats in the feed. For example there is an Atom field giving a link to the search service, some yahoo/media tags, etc. So if you use my code to parse the RSS feed, it's going to ignore that content (unless you're viewing this after Thursday as I should have updated my utility library by then). But for the most part they're not required but if you would like, just parse those fields yourself.

Anyway, that's it to searching Hulu. It's rather simple and straightforward. So give it a try, leave feedback, and happy coding.



Comments