Google has released a YouTube SDK for .NET (MSI) for those interested in programmatically accessing YouTube from a .NET or ASP.NET application.
The SDK contains a CHM help file for the YouTube API, a Visual Studio 2008 template and several application samples demonstrating the API possible usage: a tool for uploading video files to YouTube, an ASP.NET mini-website using AuthSub, an authorization service supported by YouTube, and an application which notifies on selected user YouTube activity.
The YouTube API is built on top of Google’s GData protocol (MSI), extending it with specific data classes contained in the Google.GData.YouTube
namespace. GData is an open source protocol for web communication and used extensively by Google for many of its services: Blogger, Calendar, Picasa, YouTube, and others.
The following code sample taken from the SDK’s help file shows the usage of LINQ’s chained where clause in the context of accessing YouTube:
YouTubeRequestSettings settings = new YouTubeRequestSettings("NETUnittests", YTCLIENTID, YTDEVKEY); YouTubeRequest f = new YouTubeRequest(settings); settings.AutoPaging = true; settings.Maximum = 200; //only 75 come back but that is a feature Feed<Video> sfeed = f.GetStandardFeed(YouTubeQuery.MostPopular); //put the entire list into a list. var entries = sfeed.Entries.ToList(); var oneHunderTitles = from e in entries where e.ViewCount > 100 where e.Rating > 2 where e.Updated < new DateTime(2008, 12, 4) orderby e.Rating descending orderby e.Title select e; foreach (var item in oneHunderTitles) { Console.WriteLine(item.Title); } //here is an inline orderby on title as a lambda foreach (var item in entries.OrderBy(i => i.Title)) { Console.WriteLine(item.Title); } Console.WriteLine(sfeed.Entries.Count());