Using OData to get Mix10 files
Posted
by Jon Dalberg
on Geeks with Blogs
See other posts from Geeks with Blogs
or by Jon Dalberg
Published on Thu, 06 May 2010 13:03:52 GMT
Indexed on
2010/05/11
2:55 UTC
Read the original article
Hit count: 339
There has been a lot of talk around OData lately (go to odata.org for more information) and I wanted to get all the videos from Mix ‘10: two great tastes that taste great together. Luckily, Mix has exposed the ‘10 sessions via OData at http://api.visitmix.com/OData.svc, now all I have to do is slap together a bit of code to fetch the videos.
Step 1
(cut a hole in the box)
Create a new console application and add a new service reference.
Step 2
(put your junk in the box)
Write a smidgen of code:
1: static void Main(string[] args)
2: {
3: var mix = new Mix.EventEntities(new Uri("http://api.visitmix.com/OData.svc"));
4:
5: var files = from f in mix.Files
6: where f.TypeName == "WMV"
7: select f;
8:
9: var web = new WebClient();
10:
11: var myVideos = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), "Mix10");
12:
13: Directory.CreateDirectory(myVideos);
14:
15: files.ToList().ForEach(f => {
16: var fileName = new Uri(f.Url).Segments.Last();
17: Console.WriteLine(f.Url);
18: web.DownloadFile(f.Url, Path.Combine(myVideos, fileName));
19: });
20: }
Step 3
(have her open the box)
Compile and run.
As you can see, the client reference created for the OData service handles almost everything for me. Yeah, I know there is some batch file to download the files, but it relies on cUrl being on the machine – and I wanted an excuse to work with an OData service.
Enjoy!
© Geeks with Blogs or respective owner