2012-07-17, 23:32
Is this possible? I would like to use my remote to open an addon directly.
(2012-07-18, 10:20)Montellese Wrote: I have a pull request for this (see PR821) but never really got much feedback on it. But I will most likely pull it in in the next merge window in August. That will allow you to call Addons.ExecuteAddon() on any installed addon but you'll need to know the parameters expected by the addon.
(2012-08-27, 14:53)Fahr Wrote: Alright, I guess I don't have to point our your own work to you then very nice job btw! I like the new APIHehe, glad you like it.
(2012-08-27, 14:53)Fahr Wrote: Yeah, the simplest way to handle it would probably having the entry point as __main__ in jsonrpc.py (or whatever) and pass the function name called to that. __main__ can then pass it on to a specific handling function, or handle it right there. Easy enoughYup that's what I imagine as well.
(2012-08-27, 14:53)Fahr Wrote: I don't see why it's a problem where (which thread) executes the function, or what the current context is (video playing, or something else entirely). The current API defines a number of functions which are dependent on the XBMC context. Functions like Player.SetAudioStream should only work when a video is playing, so apparently there is some handling for that in place already. I can imagine it will simply do nothing if no video is on. Similarly, the current subtitles addon (I keep coming back to it, because it's a nice example) can only be executed while playing a video (I think), so there must be some context-awareness going on there already.The context-awareness is done by the implementation of the JSON-RPC method so the addon would have to do all that as well. Just means a bit more work for the addon developer.
(2012-08-27, 14:53)Fahr Wrote: I also figure that Player.SetAudioStream will be executed in the webserver context (or at least called there) and somehow the information makes it back to the playing video. So is the thread a problem? Surely here is some sort of messaging system in place?I probably didn't make myself clear enough. XBMC's python implementation works in a way that every script runs in its own thread belonging to the threadpool in XBPython and are run asynchronously to the rest of XBMC (GUI etc). If a client sends a JSON-RPC request to the webserver, the webserver creates a new thread to handle this request and the respective JSON-RPC method should also be executed in this thread. So that doesn't really play nice with the asynchronous nature of XBPython. I've done this kind of thing already when I wanted to add python script support for webinterfaces (PS I succeeded but never cleaned up the work) and first tried running the python scripts through XBPython. But that resulted in very long response times because the script isn't directly started. It is first passed to XBPython which then launches the script whenever it feels "ready". Applying that experience to JSON-RPC methods handled by python scripts would result in response times of 4-5 seconds for a simple request which is IMO unacceptable. Like I said I have the code/logic that is necessary to solve this but I stopped working on it because I wanted to wait for jcarroll's python/codegeneration work to go in first (there's a PR for it and it looks good AFAICT).
(2012-08-27, 14:53)Fahr Wrote: A logical flow from my point of view (which is fairly limited right now, as I'm still going over the XBMC sources) for, for instance subtitles, would be;Yeah that sounds about right and should be doable. As mentioned above it's probably best to wait for jcarroll's changes to the python/addon framework because it will probably break the code/logic necessary to get synchronous python script execution.
- An addon gets enabled, the XML indicates it has a JSON interface, the JSON schema gets loaded into the Addons.[whatever] namespace
- A remote control which specifically handles the interface of said addon (this is a must) introspects the plugin and finds the functions it expects, then enables the functions in the GUI
- The remote sends a request to the addon, for instance "find subtitles for playing episode" (Addons.Subtitles.search or similar)
- The webserver gets the request, figures out it has to go to he subtitles addon and calls __main__ in jsonrpc.py with param "search"
- jsonrpc.py does whatever it has to do; generates a list of subtitle providers and subtitles found, sends it back to the webserver thread, which sends the info to the remote. The popup it normally generates on screen will not appear as it's all handled remotely.
- The remote renders the info however it sees fit, allowing the issuing of more functions. The user selects a subtitle for download, the client sends Addons.Subtitles.download(xyz).
- The webserver sends the request to jsonrpc.py __main__, which handles the download and whatever it has to do. Once it's downloaded, it can auto-issue whatever command is usually issued for SetSubtitle to set it.
It's a very rough idea and I'm probably missing a lot about scope and threads, but that's globally how I would make it work.
Doable? I'm, as stated before, more than willing (and capable) to contribute some code as well
(2012-08-27, 15:11)Montellese Wrote: The context-awareness is done by the implementation of the JSON-RPC method so the addon would have to do all that as well. Just means a bit more work for the addon developer.
(2012-08-27, 15:11)Montellese Wrote: I probably didn't make myself clear enough. XBMC's python implementation works in a way that every script runs in its own thread belonging to the threadpool in XBPython and are run asynchronously to the rest of XBMC (GUI etc). If a client sends a JSON-RPC request to the webserver, the webserver creates a new thread to handle this request and the respective JSON-RPC method should also be executed in this thread. So that doesn't really play nice with the asynchronous nature of XBPython. I've done this kind of thing already when I wanted to add python script support for webinterfaces (PS I succeeded but never cleaned up the work) and first tried running the python scripts through XBPython. But that resulted in very long response times because the script isn't directly started. It is first passed to XBPython which then launches the script whenever it feels "ready". Applying that experience to JSON-RPC methods handled by python scripts would result in response times of 4-5 seconds for a simple request which is IMO unacceptable. Like I said I have the code/logic that is necessary to solve this but I stopped working on it because I wanted to wait for jcarroll's python/codegeneration work to go in first (there's a PR for it and it looks good AFAICT).