xbmc
A short demonstration about how to use NetIO to control XBMC over the HTTP interface.
描述
XBMC has a very powerful api for controlling everything xbmc can do.
It is well documented on http://wiki.xbmc.org/index.php?title=JSON-RPC_API/v6
This api needs to be enabled
System -> Settings -> Services -> Webserver -> Allow control of XBMC via HTTP
Connection Port in the NetIO Controller App has to be the same like here and connection protocol has to be “http”
generell structure
Every command beginns with /jsonrpc?request=JSON
The JSON is like {“jsonrpc”: “2.0”, “method”: "COMMAND“, ”id": 1}
where the COMMAND is one of the JSON-RPC API methods.
Simple InputCommands
First I want to control main functions like up, down, select, home, etc.
Therefore you have to choose one of the input methods like “Input.Home”.
Because the app needs escaped JSONs you have to encode this command as URL using e.g.
http://www.ulimatbach.de/links/url_decoder.html
so we get the escaped json
and as httpCommand we can use in the app
so a button sending a simple command looks like this
Reading Values
To read some values we have to send additional information what we want to read. So for the title I want to read what the video player is actually playing. All Players (video, music, photos) have different IDs, so here i will do it for video with playerID 1.
I use the “Player.GetItem” method and add the “params” array containg information like playerid and properties array. The properties array contains which information xbmc will return.
now we are ready to build the command like before.
when we build the hole url manually we have to put http://ip:port + this command in the browser and get an answer like this:
I used this regex validator to test different regexes and found out that i need the look ahead function of regex. Now we have our parseResponse attribute:
so a label reading a title looks like this
It is well documented on http://wiki.xbmc.org/index.php?title=JSON-RPC_API/v6
This api needs to be enabled
System -> Settings -> Services -> Webserver -> Allow control of XBMC via HTTP
Connection Port in the NetIO Controller App has to be the same like here and connection protocol has to be “http”
generell structure
Every command beginns with /jsonrpc?request=JSON
The JSON is like {“jsonrpc”: “2.0”, “method”: "COMMAND“, ”id": 1}
where the COMMAND is one of the JSON-RPC API methods.
Simple InputCommands
First I want to control main functions like up, down, select, home, etc.
Therefore you have to choose one of the input methods like “Input.Home”.
{"jsonrpc":"2.0","method":"Input.Home","id":1}
Because the app needs escaped JSONs you have to encode this command as URL using e.g.
http://www.ulimatbach.de/links/url_decoder.html
so we get the escaped json
%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22Input.Home%22%2C%22id%22%3A1%7D
/jsonrpc?request=JSON%7B%22jsonrpc%22%3A%222.0%22%2C%22method%22%3A%22Input.Home%22%2C%22id%22%3A1%7D
so a button sending a simple command looks like this
{ "sends": [ "/jsonrpc?request=%7B%22jsonrpc%22%3A+%222.0%22%2C+%22method%22%3A+%22Input.Home%22%2C+%22id%22%3A+1%7D" ], "top": 50, "height": 40, "width": 60, "shape": "circle", "label": "Home", "type": "button", "left": 60 }
Reading Values
To read some values we have to send additional information what we want to read. So for the title I want to read what the video player is actually playing. All Players (video, music, photos) have different IDs, so here i will do it for video with playerID 1.
I use the “Player.GetItem” method and add the “params” array containg information like playerid and properties array. The properties array contains which information xbmc will return.
{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title"], "playerid": 1 }, "id": "VideoGetItem"}
now we are ready to build the command like before.
/jsonrpc?request=%7B%22jsonrpc%22%3A+%222.0%22%2C+%22method%22%3A+%22Player.GetItem%22%2C+%22params%22%3A+%7B+%22properties%22%3A+%5B%22title%22%5D%2C+%22playerid%22%3A+1+%7D%2C+%22id%22%3A+%22VideoGetItem%22%7D
when we build the hole url manually we have to put http://ip:port + this command in the browser and get an answer like this:
{"id":"VideoGetItem","jsonrpc":"2.0","result":{"item":{"id":3,"label":"Batman Begins","title":"Batman Begins","type":"movie"}}}
I used this regex validator to test different regexes and found out that i need the look ahead function of regex. Now we have our parseResponse attribute:
(?<=title":")[^"]+
so a label reading a title looks like this
{ "text": "title", "top": 270, "height": 40, "width": 260, "reads": "/jsonrpc?request=%7B%22jsonrpc%22%3A+%222.0%22%2C+%22method%22%3A+%22Player.GetItem%22%2C+%22params%22%3A+%7B+%22properties%22%3A+%5B%22title%22%5D%2C+%22playerid%22%3A+1+%7D%2C+%22id%22%3A+%22VideoGetItem%22%7D", "parseResponse": "(?<=title\":\")[^\"]+", "type": "label", "formatResponse": "{0}", "left": 30, "interval": 3000 }