looking for JSON API example... and solution.

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
nanouk76 Offline
Junior Member
Posts: 40
Joined: Aug 2011
Reputation: 1
Post: #1
Hi all,
I'm trying to have the PC with the database shutdown automatically if it doesn't detect any of its clients are streaming media via XBMC.
Reading this and this shed very little light on a potential solution though I suspect it's doable. Very frustrating. I'm the kind to learn by example and don't find the documentation very helpful in that respect. Thus I need help getting a real life example of what can be done with this API regarding what I'm trying to achieve.
TIA

ASUS Motherboard M5A78L-M/USB3 // 8 GB RAM
Nvidia GeForce GT 430 graphics card // 2 GB RAM
Ubuntu upgraded to 12.04 LTS
XBMC v.11 Eden
find quote
wuench Offline
Member
Posts: 56
Joined: Dec 2010
Reputation: 0
Post: #2
It is a bit of a climb to understand the API docs. I recommend you build the foundations and send examples with your player in various states. You can do it with TCP sockets or you can use the HTTP interface, but you will need to send a POST not a GET to http://yourpc/jsonrpc, so you can't just use a browser. That was the method I followed in writing my XBMC driver for CQC.

Specifically I think the following command and example response will tell you if a player is active and which one:

Code:
COMMAND: {"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":1}

RESPONSE: {"id" : 1, "jsonrpc" : "2.0", "result" : { "audio" : false,"picture" : true, "video" : false }}
(This post was last modified: 2012-05-05 15:03 by wuench.)
find quote
nanouk76 Offline
Junior Member
Posts: 40
Joined: Aug 2011
Reputation: 1
Post: #3
(2012-05-05 15:02)wuench Wrote:  It is a bit of a climb to understand the API docs. I recommend you build the foundations and send examples with your player in various states. You can do it with TCP sockets or you can use the HTTP interface, but you will need to send a POST not a GET to http://yourpc/jsonrpc, so you can't just use a browser. That was the method I followed in writing my XBMC driver for CQC.

Specifically I think the following command and example response will tell you if a player is active and which one:

Code:
COMMAND: {"jsonrpc":"2.0","method":"Player.GetActivePlayers","id":1}

RESPONSE: {"id" : 1, "jsonrpc" : "2.0", "result" : { "audio" : false,"picture" : true, "video" : false }}
Sorry to be such a noob but what do I do with that using curl for example if i want to query IP 192.168.0.50?
This is what I tried :
Code:
~$ curl --data-binary '{ "jsonrpc": "2.0", "method": "GetActivePlayers", "id":1}' -H 'content-type: application/json;' http://192.168.0.50:9000/jsonrpc

<html>
    <head>
    <title>Access denied</title>
    </head>
    <body>
    <br/><br/>
    <font color="#0000FF">Error 401 Unauthorized: You need to provide a valid username and password.</font>
    </body>
</html>
A bit of a shot in the dark I know. I'm surprised at the error though since XWMM connects fine to the IP. I left xbmc as user without a password on the settings page.

ASUS Motherboard M5A78L-M/USB3 // 8 GB RAM
Nvidia GeForce GT 430 graphics card // 2 GB RAM
Ubuntu upgraded to 12.04 LTS
XBMC v.11 Eden
(This post was last modified: 2012-05-05 16:15 by nanouk76.)
find quote
wuench Offline
Member
Posts: 56
Joined: Dec 2010
Reputation: 0
Post: #4
I haven't tried it with curl. But the syntax looks right to me. Are you sure 9000 is the correct port, the default web server port is usually 8080. I think 9000 is for TCP socket connections.
find quote
nanouk76 Offline
Junior Member
Posts: 40
Joined: Aug 2011
Reputation: 1
Post: #5
(2012-05-05 19:11)wuench Wrote:  I haven't tried it with curl. But the syntax looks right to me. Are you sure 9000 is the correct port, the default web server port is usually 8080. I think 9000 is for TCP socket connections.
You're right, I got the port wrong. I changed it to 8085. So this is what I get now:
Code:
{"error":{"code":-32601,"message":"Method not found."},"id":1,"jsonrpc":"2.0"}
So I guess "GetActivePlayers" in not the right method... It's "Player.GetActivePlayers". Now I get this:
Code:
{"result":[{"playerid":1,"type":"video"}]}
Making progress...

ASUS Motherboard M5A78L-M/USB3 // 8 GB RAM
Nvidia GeForce GT 430 graphics card // 2 GB RAM
Ubuntu upgraded to 12.04 LTS
XBMC v.11 Eden
find quote
wuench Offline
Member
Posts: 56
Joined: Dec 2010
Reputation: 0
Post: #6
Yep that's right. Sorry I forgot that command's response changed with Eden, the example I posted was from Dharma.
find quote