Posts: 11
Joined: Mar 2016
Reputation:
0
Hi there
I want to develop an add-on for Kodi that will need to take instructions (via network, probably using HTTP/REST) and interact with Kodi. I'm wondering what's the best (or only) way to go about it.
Does Kodi have a way to run an add-on like this (as if it's a service, so indefinitely) and allow it to interact with Kodi (so using xbmc, etc. modules)?
If not, from what I read, it looks like the only way to interact with Kodi by not using the Python modules is via the JSON-RPC API?
What type of extension like this does Kodi class it as? Would that be an add-on, script, etc?
Posts: 1,665
Joined: Jun 2011
Reputation:
119
If the features of Kodi JSON-RPC API are not enough for you, Kodi includes a full-featured Python (or more exactly, CPython) runtime, so you can use any Python libraries for your purposes. I guess, you can even use Django inside Kodi, but that would be a huge overkill for any purpose. The only recommendation is not to use Python libraries which include binary components. Technically, you can use such libraries but maintaining such addon is real PITA, especially if you want to support several platforms.
As for addon type, you need a service addon that will run in the background, hosting your network server. In this case it is strongly recommended for your service to periodically poll xbmc.abortRequested flag so that your server could be gracefully terminated along with Kodi.
Posts: 11
Joined: Mar 2016
Reputation:
0
Thanks for that. A service extension sounds like that's exactly what I need, and I can just import the Kodi Python modules. Would there be any disadvantage to doing that instead of using the JSON-RPC API or any other way?
All the service needs to do is listen for REST/HTTP and also act on various Kodi events.
Posts: 7,650
Joined: Jun 2011
Reputation:
287
if the json api provides all you need to interact with kodi, your rest stuff can also live outside of kodi as a kind of proxy.
Posts: 11
Joined: Mar 2016
Reputation:
0
2016-03-27, 04:38
(This post was last modified: 2016-03-27, 04:43 by jgivings.)
I might elaborate on my project a bit more. It's actually part of an academic study. The plan is to put Kodi boxes (probably on Raspberry Pi) in participants' homes and send/receive data. We'll use their existing Internet, so to send data to the boxes, we'll need to traverse NAT. Therefore, we'll need to have the boxes establish and maintain a connection to a remote server. We could use SSH forwarding, VPNs, etc., but the plan for now is to keep it lightweight and standalone.
It looks like I'll need to create a service for that reason alone. Now, the service can either be a Kodi add-on or independent. If an add-on, then I at least have the choice of importing the Kodi modules and using them directly. I could also use other methods (like JSON-RPC API), but there doesn't seem to be a good reason to, and would only increase the complexity. If an independent service, then it looks like I only have the choice of JSON-RPC API or the runtime mentioned.
The simplest option seems to be service add-on and using Kodi Python modules directly. What do you guys think?
Posts: 7,650
Joined: Jun 2011
Reputation:
287
2016-03-27, 20:46
(This post was last modified: 2016-03-27, 20:46 by wsnipex.)
given that you want to build a "phone home" system, going with a python based service addon seems reasonable.
I'd be interested in the details of the data you're looking for in this study.