problem with api: qstatus

Report & discuss bugs found in SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
emilb
Newbie
Newbie
Posts: 13
Joined: May 19th, 2009, 7:33 pm

problem with api: qstatus

Post 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
emilb
Newbie
Newbie
Posts: 13
Joined: May 19th, 2009, 7:33 pm

Re: problem with api: qstatus

Post 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
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: problem with api: qstatus

Post 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.
Last edited by shypike on May 22nd, 2009, 3:36 am, edited 1 time in total.
emilb
Newbie
Newbie
Posts: 13
Joined: May 19th, 2009, 7:33 pm

Re: problem with api: qstatus

Post 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
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: problem with api: qstatus

Post 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!
Post Reply