Getting Information from Your TiVo

10/12/2009

If you can't tell from some of the posts lately, I've been on a media kick (with a small break for multithreading and an update on some of my projects). Anyway, along with Netflix and Hulu, I own a TiVo. My marriage would not be intact if it wasn't for my TiVo. Sadly that's not a joke... Anyway, there are a number of cool things that you can do with your TiVo. Hack it, stream video from it, create apps to run on it, etc. However in my case all that I want to do is figure out what I have recorded on my box. Figuring out how to do even this was a pain, but here you go.

   1: public static class Tivo
   2: {
   3:     public static string GetShowList(string TivoAddress, string Password)
   4:     {
   5:         return GetFileContents(new Uri("https://" + TivoAddress + "/TiVoConnect?Command=QueryContainer&Container=%2FNowPlaying"), "tivo", Password);
   6:     } 
   7:  
   8:     private static string GetFileContents(Uri FileName, string UserName, string Password)
   9:     {
  10:         WebClient Client = new WebClient();
  11:         StreamReader Reader = null;
  12:         try
  13:         {
  14:             ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(IgnoreCertErrorsCallback);
  15:             Client.Credentials = new NetworkCredential(UserName, Password);
  16:             Reader = new StreamReader(Client.OpenRead(FileName));
  17:             string Contents = Reader.ReadToEnd();
  18:             return Contents;
  19:         }
  20:         catch
  21:         {
  22:             return "";
  23:         }
  24:         finally
  25:         {
  26:             if (Reader != null)
  27:             {
  28:                 Reader.Close();
  29:             }
  30:         }
  31:     } 
  32:  
  33:     private static bool IgnoreCertErrorsCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  34:     {
  35:         return true;
  36:     }
  37: }

The code above is a bit odd but basically the way you get information from a TiVo is similar to Hulu/Netflix. It's just a web quest. However there are two things to keep in mind, the first is that the server validation will always come back with an error. I have no idea why, but it always comes back with an error. As such you have to override the certification validation callback. At the same time you have to send your credentials to the TiVo. The credentials would be your username, which is always tivo, and your password, which is your media access key associated with your tivo. Past that, it's just a call to your tivo and you'll get back an XML file. I'm still working on parsing it but the code above simply returns the XML file. Anyway, hopefully the code above will be of some use to someone. So try it out, leave feedback, and happy coding.



Comments