TiVo Community
TiVo Community
TiVo Community
Go Back   TiVo Community > Underground Playground > Developers Corner
TiVo Community
Reply
Forum Jump
 
Thread Tools
Old 03-18-2016, 03:59 PM   #1
Eric2XU
Registered User
 
Join Date: Mar 2016
Posts: 13
Which TiVo API for Show List and Forced Playing on TiVo

Hey all,

I recently setup my Amazon Echo to Control my Harmony Hub. Got a few sweet NodeJS apps in the middle that glue it all together. Works great for doing what a controller can do.

However I really want to take things to the next level.

I want to be able to say "Alex tell TiVo to play the daily show" and in turn my code would go looking for a show called the daily show, figure out which one is latest, then tell the TiVo to put it on.

I know this is possible as kmttg is able to both get a list of shows as well can remote trigger playing of a show.

Can anyone help me figure out how to do it? I am assuming its some sort of web call? Given its encrypted I am unable to sniff the traffic on kmttg

Eric2XU is offline   Reply With Quote
Old 03-18-2016, 04:20 PM   #2
Eric2XU
Registered User
 
Join Date: Mar 2016
Posts: 13
Ok already learned a few things. First kmttg is using MindRPC on port 1413.

This is some sort of ssl based JSON which requires a client certificate. What I dont understand is how kmttg got that cert and could I use the cert in kmttg?

Next I have zero idea where to learn what type of communications MindRPC is actually doing let alone do it in NodeJS.

Anyone have any guidance?

Eric2XU is offline   Reply With Quote
Old 03-18-2016, 09:36 PM   #3
gonzotek
tivo_xml developer
 
gonzotek's Avatar
 
Join Date: Sep 2004
Location: Outside Phildadelphia
Posts: 2,372
Hmm interesting project ..it might actually be a lot simpler to leverage the work kmttg already does...it has a web server component that you could probably consume and interact with via node fairly easily. The one thing we'd need that it doesn't do yet (but I'm sure it could be made to) is start playback on the TiVo from the web ui. If you're interested in this route, I'd talk to Kevin in the kmttg thread about adding a 'play on tivo' option to the stream.htm page of kmttg. Beyond this project I can see other times I'd want the same playback option available via the web ui. And I'd be up for testing and maybe even helping with the code for this too!

There's not really much MindRPC documentation, much of what is known about it is in the kmttg source (and kmttg thread above and this one from the tivo underground forum). The cert is another issue too..

Btw, I have one but haven't gotten around to Echo programing just yet; but I am using harmonyhubjs-client as the basis for a script syncing my two hubs' activities ;-) One remote for me, one for the wife

__________________
Follow @pytivo on Twitter for project updates and more!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
A Web app for Roku Remote Control
gonzotek is offline   Reply With Quote
Old 03-20-2016, 08:13 PM   #4
Eric2XU
Registered User
 
Join Date: Mar 2016
Posts: 13
Thanks gonzotek!

I am going to give MindRPC via Nodes TLS module a try. I was able to get a certificate private key and password (for reasons of not upsetting anyone I am not going to go into details on that part).

It may be a few days before I have time to give it a go but will see if I can get that to work. The idea of being able to query TiVo directly, get back JSON, and take action is too good to pass up. Given my limited code abilities I may still fail to do so. If I do I would be super happy to help and try to get play put in the web UI. That would likely be enough to use it as a middleware.

Anyways thanks again for posting back, will let you know how it goes. I will gladly share anything I learn.

Eric2XU is offline   Reply With Quote
Old 03-21-2016, 11:39 AM   #5
Eric2XU
Registered User
 
Join Date: Mar 2016
Posts: 13
So I took a little more time on my lunch break today and I am a little stuck.

If I run curl against the tivo using the certs I pulled from another project (which I am 99% sure are valid) I get "Unknown CA" I get the same message using Node JS TLS connect method with the certs, using Wireshark I can decrypt the exchange using the private key and see the TiVo responding with:

Transmission Control Protocol, Src Port: 1413 (1413), Dst Port: 53699 (53699), Seq: 4331, Ack: 2015, Len: 7
Secure Sockets Layer
TLSv1.2 Record Layer: Alert (Level: Fatal, Description: Unknown CA)
Content Type: Alert (21)
Version: TLS 1.2 (0x0303)
Length: 2
Alert Message
Level: Fatal (2)
Description: Unknown CA (48)

Here is the CURL output as well.

slice@pi:/var/tmp$ curl -k --cert tivo.cert \
> --key tivo.key \
> -H 'Accept: application/json' \
> 'https://10.0.0.32:1413/mind/mind11?type=infoGet' \

curl: (35) error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca

Anyone have any thoughts? Will pick up again in another day or so, got to get back to work. My only thought is I screwed something up splitting the p12 file into cert and key files although they seem valid enough to be used to decrypt in wireshark. Perhaps I need to supply the full chain in the cert? Although I am not sure how to include more then one public cert in a pem (cert) file.


Last edited by Eric2XU; 03-21-2016 at 12:00 PM.
Eric2XU is offline   Reply With Quote
Old 03-21-2016, 01:03 PM   #6
Eric2XU
Registered User
 
Join Date: Mar 2016
Posts: 13
Ok final update for the day, I think I am past the SSL issues. Adding all public certs in the chain to my .cert file seems to have made the key exchange happy.

I simply can not wrap my head around MPRC. Its not https but its similar. So instead of using the HTTPS library I am using the TLS for node. I open a connection to port 1413, I past in a header payload from the examples here:

docs.google.com/document/pub?id=1e4ymm7ROwmW6co2pKENjANGT5xM00VzmzybZ4u8yDE8#h.5befa7 kbkyui

And I get nothing back. Here is my code if anyone is interested. If I can simply figure out how to communicate back and forth with with the TiVo I would be home free:

Code:
var tls = require('tls');
var fs = require('fs');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

var header = (function () {/*
MRPC/2 225 85
Type:request
RpcId:20
SchemaVersion:7
Content-Type:application/json
RequestType:bodyAuthenticate
ResponseCount:single
BodyId:
X-ApplicationName:Quicksilver
X-ApplicationVersion:1.2
X-ApplicationSessionId:0x27dc20
*/}).toString().replace('function () {/*', '').replace('*/}', '').trim();

console.log("----------");
console.log(header);
console.log("----------");


var options = {
	host : "192.168.1.10"
	,port : 1413
	,headers: header
	,key  : fs.readFileSync('c:\\temp\\tivo.key')
	,cert : fs.readFileSync('c:\\temp\\tivo.cert')
};

var client = tls.connect(options, function () {
	client.write('{"type":"bodyAuthenticate","credential":{"type":"makCredential","key":"1234567890"}}');
});

client.on('data', function (data) {
	console.log(data.toString());
	client.end();
});


Last edited by Eric2XU; 03-21-2016 at 01:22 PM.
Eric2XU is offline   Reply With Quote
Old 04-01-2016, 01:00 PM   #7
Eric2XU
Registered User
 
Join Date: Mar 2016
Posts: 13
All done!

Ok final post, got it all working.

Here's the deal.

First you need to authenticate to the TiVo. This is pretty simple after you get over the amazing hurdle about the custom protocol. This makes most off the shelf libraries useless. I used Node.js's TLS library which is a SSL wrapper for their direct socket (net) library. Once you have the language sorted, you have create a custom header and body. The first line is special as well, you put MRPC/2 which tells it the version of protocol, next number is the total number or characters in the header including the \r\n (blank line) between the header and body which is part of the header. Final number on the first line is the total characters in the body. Oh and the cert, I dont want to go into details to not piss off TiVo but I do the same thing other projects (sorry for the lack of detail there). Its down right stupid TiVo doesn't have a public API.
Code:
MRPC/2 235 85

Type: request
RpcId: 1
SchemaVersion: 17
Content-Type: application/json
RequestType: bodyAuthenticate
ResponseCount: single
BodyId:
X-ApplicationName: Quicksilver
X-ApplicationVersion: 1.2
X-ApplicationSessionId: 0x27b520

{"type":"bodyAuthenticate","credential":{"type":"makCredential","key":"<TiVoMACKey>"}}
Then the trick is not to close the socket, you have to turn right around on the same connection for the rest of your requests. Each new request you keep the seasonId, change the type to whatever type you are using (type is also in the body) and rev the RpcID by 1.

Oh the sessionID is a number within a range, forget the range but this is the code I use:
Code:
var sessionID = Math.floor(Math.random() * (2612256 - 2539520) + 2539520).toString(16)
Next do a recordingFolderItemSearch to return all parent folder recordings, I set flatten to false so the return is small and manageable:
Code:
"flatten":false,"offset":0,"bodyId":"tsn:848xxxxxxxxxx","type":"recordingFolderItemSearch"}
You will need the TSN for that, if you dont have it you can run this:
Code:
{ "type": "bodyConfigSearch", "bodyId": ""}
Next you loop that looking for a match on results.recordingFolderItem[x].title. Once you find that you are looking for the collectionID and folderItemCount of that record. Go back to the TiVo and run a recordingSearch as many times is equal to folderItemCount. Yup thats right you have to rerun the query as many times as there are recordings (folderItemCount):
Code:
'{"bodyId":"tsn:848xxxxxxxxxx","collectionId": "<collectionId>","type":"recordingSearch","offset":<folderItemCount++>}
You are going to be looking for the results.recording[x].recordingId for the specific show you want to play. Once you have it run uiNavigate on the TiVo:
Code:
{ "type":"uiNavigate", "uri":"x-tivo:classicui:playback", "parameters": { "fUseTrioId":"true", "fHideBannerOnEnter":"false", "recordingId":"<recordingId>"}}
That should be it. Hope it helps anyone else that needed to get a jump start on coding for the TiVo.

Eric2XU is offline   Reply With Quote
Thanks For This Post:
Reply
Forum Jump







Thread Tools


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Advertisements





TiVo Community
Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.
vBulletin Skins by: Relivo Media


(C) 2016 DBNet - All Rights Reserved. No information may be posted elsewhere without written permission.
TiVoŽ is a registered trademark of TiVo Inc. This site is not owned or operated by TiVo Inc.
All times are GMT -5. The time now is 03:44 PM.
Page generated in 0.15404797 seconds (53.91% PHP - 46.09% MySQL) with 18 queries