API over HTTP with different outputs (JSON, HTML)
#1
I like to modify libGoAhead\XBMChttp.cpp so it also support JSON output.
So it will be easier to create ajax homepage to remote control the XBMC.

I like to modify the function SetResponse so it takes an object with list of values so it will be easier to write new output format like XML.

I need to modify every function that call SetResponse.
Should I send someone these files or can I insert it to svn.
It is my first time that I'm programing for open source.

example:
http://xbox/xbmcCmds/xbmcHttp?command=ge...yPlaying()
# Filename:E:\HD Movie\300.mkv
# PlayStatusTonguelaying
# VideoNo:0
# Type:Video
# Title:300
# Genre:Guy Movie / Mature / Violence / Blockbuster / Fantasy Film / Low Fantasy / Pseudohistorical Fantasy / Hollywood Film / Literary Fiction / Comic / Adventure Film / Historical Film / Sword and Sandal / Action Film
# Director:Zack Snyder
# Writer:Frank Miller
# Plot:Based on Frank Miller's graphic novel, "300" concerns the 480 B.C. Battle of Thermopylae, where the King of Sparta led his army against the advancing Persians; the battle is said to have inspired all of Greece to band together against the Persians, and helped usher in the world's first democracy.
# Rating:8.0 ( votes)
# Year:2006
# ThumbConfusedpecial://masterprofile/Thumbnails/Video/7/78769881.tbn
# Time:00:00:41
# Duration:01:56:32
# Percentage:0
# File size:4693522403
# Changed:False
---------------------
http://xbox/xbmcCmds/xbmcHttp?output=jso...yPlaying()
{"Filename":"E:\\HD Movie\\300.mkv",
"PlayStatus":"Playing",
"VideoNo":0,
"Type":"Video",
"Title":"300",
"Genre":"Guy Movie / Mature / Violence / Blockbuster / Fantasy Film / Low Fantasy / Pseudohistorical Fantasy / Hollywood Film / Literary Fiction / Comic / Adventure Film / Historical Film / Sword and Sandal / Action Film",
"Director":"Zack Snyder",
"Writer":"Frank Miller",
"Plot":"Based on Frank Miller's graphic novel, \"300\" concerns the 480 B.C. Battle of Thermopylae, where the King of Sparta led his army against the advancing Persians; the battle is said to have inspired all of Greece to band together against the Persians, and helped usher in the world's first democracy.",
"Rating":"8.0 ( votes)",
"Year":2006,
"Thumb":"special://masterprofile/Thumbnails/Video/7/78769881.tbn",
"Time":"00:00:41",
"Duration":"01:56:32",
"Percentage":0,
"File size":4693522403,
"Changed":"False"}
Reply
#2
Hi there and welcome!

You should generate a patch (using the diff command, or if you're on windows, use Tortoise to generate a patch) and create a ticket on trac and attach your changes, why they were made, what it does etc.

A developer will review it from there. Thanks for your contribution!

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#3
magni.thor: are you sure the SetResponseFormat httpapi command can't provide what you are after?

Reply
#4
nad: SetResponseFormat is good function but I like to control the output more than that.
like for example function SetVolume
int CXbmcHttp::xbmcSetVolume(int numParas, CStdString paras[])
{
if (numParas<1)
return SetResponse(openTag+"Error:Missing Parameter");
else
{
int iPercent = atoi(paras[0].c_str());
g_application.SetVolume(iPercent);
return SetResponse(openTag+"OK");
}
}
the result from this function will be "<li>Erro:Missing Parameter" or "<li>OK"
but for the JSON it need to be "{"Error":"Missing Parameter"} or {"Action":"ok"}

How to you like this idea to add this function to the project?
Reply
#5
magni.tor:

I use JSON for my tool here.

I wrote a small function to parse the XML tags (look in my xbmc.js)

Kabooga wrote something similar to parse the <li> tags (probably what you need) here

If you are familiar with python coding, you could also do from the server side using spyce (Python Server Page).

Good luck and thanks in advance for your contribution.
Reply
#6
Just a fyi I have started working on a httpapi replacement, the first version will sport jsonrpc interface.
If you have problems please read this before posting

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

Image

"Well Im gonna download the code and look at it a bit but I'm certainly not a really good C/C++ programer but I'd help as much as I can, I mostly write in C#."
Reply
#7
First I started to write php script that walked through html page and changed it to JSON for my ajax mobile homepage to control the XBMC. Then I thougt why not to change the XBMC so everybody can use. Then I build an abstract class that every function in the class CXbmcHttp use to create the output. Now I have taken about 25% of the function and have written 3 class CResponseOutputHTML = this will have the same result as it is now, CResponseOutputJSON = JSON object, CResponseOutputXML = XML object.

Code:
class CResponseOutput
{
public:
  virtual CResponseOutput* addItemString(const CStdString &field, const CStdString &value, const bool useField = true, const bool useValue = true ) = 0;
  virtual CResponseOutput* addItemBool(const CStdString &field, const bool &value, const bool useField = true, const bool useValue = true ) = 0;
  virtual CResponseOutput* addItemInt(const CStdString &field, const int &value, const bool useField = true, const bool useValue = true ) = 0;
  virtual CResponseOutput* addItemFloat(const CStdString &field, const float &value, const bool useField = true, const bool useValue = true ) = 0;
  virtual void Clear() = 0;
  virtual CStdString GenerateOutput() = 0;
  virtual DWORD getOutputType() = 0;
};

old:
Code:
int CXbmcHttp::xbmcGetVolume()
{
  CStdString tmp;
  tmp.Format("%i",g_application.GetVolume());
  return SetResponse(openTag + tmp);
}

new:
Code:
int CXbmcHttp::xbmcGetVolume(CResponseOutput* responseOutput)
{
  return SetResponse(responseOutput->addItemInt("Volume", g_application.GetVolume(), false));
}

Output example

output html
Quote:<html>
<li>100</html>
output json
Quote:{"Volume":100}
output xml
Quote:<XBMC><Field name="Volume">100</Field></XBMC>


topfs2 how is your idea to change this httpapi?
Do you think xbmc community will not use this patch if I will finish this after one or two weeks and the default output will still be same as it is now?
Reply
#8
magni.tor: I have no idea how useful people will find your modification. I don't think parsing the httpapi output is a big deal for most people. All I ask is that if you do submit a patch that you don't change the default behaviour which is what you have said already so good luck.

Reply
#9
Actually I would find this pretty useful. I'm thinking of working on a new web ui that would be heavy on the ajax and having an option to send the response in JSON will help with performance on the client. For me it would mean the data parsing would be done internally by the javascript processor on the browser instead of implementing the post processing in javascript.

In an ideal world I would like to see a RESTful implementation for an API, see my comments on #8072.
Reply

Logout Mark Read Team Forum Stats Members Help
API over HTTP with different outputs (JSON, HTML)0