Page 1 of 1

problem with api: qstatus

Posted: May 21st, 2009, 5:43 pm
by emilb
Hi,

I'm writing a third-party application that will manage my downloads (see: http://wiki.github.com/emilb/TvSeriesNZ ... -and-setup )

As a part of this app I now want to add a check sequence that verifies that the configuration regarding SABnzbd is correct. My plan is to show the result from the qstatus query via the API. As usual I try the command with wget and I'm not getting parseable results. See examples below.

JSON:
wget -qO- "http://localhost:8080/sabnzbd/api?mode= ... utput=json"

gives:
{"have_warnings":"3","timeleft":"0:58:11","mb":4816.505752,"noofslots":1,"paused":false,"mbleft":4175.837344,"diskspace2":583.092541,"diskspace1":583.092541,"kbpersec":1224.630289,"jobs":[{"msgid":"4996513","filename":"Ong bak 2 (2008) (Thai)","mbleft":4175.837344,"id":"SABnzbd_nzo_844aHB","mb":4816.505752}]}

XML:
wget -qO- "http://localhost:8080/sabnzbd/api?mode= ... output=xml"

gives:

               
                False
                1250.88619515
                3265.23821259
                4816.50575161
                1
                582.213054657
                582.213054657
                0:44:32


                    SABnzbd_nzo_844aHB
                    4996513
                    Ong bak 2 (2008) (Thai)
                    3265.23821259
                    4816.50575161
                   


The XML variant fails when I try to parse it ( is unexcpected and not closed and no root tag).

In the JSON case it is more complete but the parser I'm using (XStream for Java) expects all elements to be named. This includes the root and job elements. As I understand the JSON specs all {...} are to be prefixed with a name which is not the case here.

What's up, is this a bug or am I doing something wrong?

wget http://localhost:8080/sabnzbd/api?mode=version 
gives:
0.4.9
running on Ubuntu 9.04 64bit

Thanks

Emil

Re: problem with api: qstatus

Posted: May 21st, 2009, 6:23 pm
by emilb
Sorry!

the xml reply is correct, is terminated correctly and all is fine. But I still wonder about the JSON issue. Is the JSON output really complaint?

/E

Re: problem with api: qstatus

Posted: May 22nd, 2009, 3:33 am
by shypike
Reading the JSON spec on http://www.json.org/ , I must disagree with you.
Objects have no name.
An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).
Can you give an example of what you think the json output should look like?

BTW: when I parse the JSON output with JsonLint (http://www.jsonlint.com/), it says it's valid json.

Re: problem with api: qstatus

Posted: May 23rd, 2009, 5:35 pm
by emilb
Okay, I was really wrong here.

Apparently the parser I was using (XStream) expects every object to be named. Something like this:

"queue":{"have_warnings":"3","timeleft":"0:58:11","mb":4816.505752,"noofslots":1,"paused":false,"mbleft":4175.837344,"diskspace2":583.092541,"diskspace1":583.092541,"kbpersec":1224.630289,"jobs":["job":{"msgid":"4996513","filename":"Ong bak 2 (2008) (Thai)","mbleft":4175.837344,"id":"SABnzbd_nzo_844aHB","mb":4816.505752}]}

This is probably so it can map the values to a defined Object in Java. When I (admittedly) glanced at the specs I read name/value pairs and considered that a list of names/values (i.e. the object) could be regarded the same way as a single name/value pair. Considering how loosely json objects are defined I find it hard to use in any practical sense together with Java but that's another story.

I'm now using the xml-output and it is working fine. One note: the have_warnings tag is missing from the xml output.

Thanks

Emil

Re: problem with api: qstatus

Posted: May 24th, 2009, 2:15 am
by shypike
You are correct about the missing field in XML.
I'll fix it, but it isn't likely that a new release will be done just for this issue.

Don't feel too bad: we welcome any constructive critical remarks!