Page 1 of 2

XBMC frodo

Posted: Tue Jan 01, 2013 3:19 pm
by tytherman
hi I noticed that a sample project for XBMC was put up to day, it seems to combine Json v2 for navigation and HTTP for Feedback? the problem is that HTTP is not supported in Frodo as far as I know so could someone help with a sample file for Frodo?

Re: XBMC frodo

Posted: Tue Jan 01, 2013 5:08 pm
by bob3695
I don't have an example project but am here to give some help in the form of some web URLs!

http://wiki.xbmc.org/index.php?title=JSON-RPC_API/v6 <- That shows you what you can request via JSON and what it returns. Armed with that information you just need to re-write the commands and the Regex for getting the feedback. I might eventually wire up a device to use the updated API but I am not using XBMC but a varient (Boxee Box) which is not on this version. If you are unfamiliar with how to do this...here is a simple explanation:

Step 1: Test outside of DemoPad. I would suggest using a tool called Hercules (http://www.hw-group.com/products/hercules/index_en.html). There is no installer, just download and launch. Switch to TCP Client tab, on the right punch in your XMBC's IP address and the port (for Boxee Box it was 9090, might have to play around with it) and hit connect.
Step 2: Once it is connected, at the bottom there are 3 different boxes you can use to send commands. Play with sending commands from the reference I gave above. (NOTE: You would use the standard suffix that DemoPad sets BUT instead of \x its $ so it would become $0D$0A instead of \x0D\x0A) You will see what the system responds with in the box above.
Step 3: Once you learn what commands you need to send to do different operations and are ready to setup the feedback portion, first send the command in Hercules and it will respond with the JSON data. Then its as simple as taking that response and applying regex to it. A good starting point for learning RegEx if you don't know it already is Regex Lib (http://regexlib.com/). You can also use the regex in the example project to help get you started (although it will change a lot).
Step 4: Once you think you have the reg ex right point your browser to http://regexlib.com/RETester.aspx and put the data XMBC returned into the 'Source' box and the regex you wrote in the regex box and hit Submit. If all the stars align and the world is perfect you will get it on the first try...but chances are you will need to tweak it. Once the data it pulls out is what you want, just put that into DemoPad
Step 5: Once 1-4 are complete and you have everything in DemoPad push it to a device and test!

Ok, long winded explanation done. If you have issues with any of the steps I just outlined let me know and I will see what I can do to help you out!

Re: XBMC frodo

Posted: Tue Jan 01, 2013 6:19 pm
by tytherman
ok this is all a bit daunting but have done step 1 I have then typed in what I found on the xbmc forums into onw of the three boxes

ie {"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":1,"properties":["title","showtitle","season","episode"]},"id":"1"}

and I get a good result with the following response

{"id":"1","jsonrpc":"2.0","result":{"item":{"episode":-1,"id":1829,"label":"Dredd","season":-1,"showtitle":"","title":"Dredd","type":"movie"}}}

the next step has me stumped... when you say "applying regex to it" I am not sure what this means?

Re: XBMC frodo

Posted: Tue Jan 01, 2013 7:51 pm
by bob3695
Ok, by applying regex I mean you need to write some regex. Regex is designed to do a few things which include, but not limited to, validation (for example when you are filling out a form online), pulling information out of a string of text (like getting the movie name out of the response you posted). So we will be using it to pull information.

Regex can be complex to learn but at its core is fairly simple. So let me walk you through pulling the info from the example response you posted. For this example we want to pull the title of the movie.

So to start we have:

{"id":"1","jsonrpc":"2.0","result":{"item":{"episode":-1,"id":1829,"label":"Dredd","season":-1,"showtitle":"","title":"Dredd","type":"movie"}}}

Which is your basic JSON object (not surprising since we are working with a JSON API) and what we want in what I have underlined above. So first thing I would suggest is hop on over to the XBMC example you referenced and hit the COnfigure 2-way button on the XBMC (FEEDBACK) device. You will notice there is a title one in there so we are going to start with that:

<li>Title:(.*)

Now <li> is an HTML tag that would have been in the HTTP API from the example but is not here so we will have to replace that. Looking at our example response we want to find the "title": section so we can pull whats after it. So we pull up the regexlib.com regex tester (link in my previous post) and start playing with some reg ex. The first change I did was switch out the <li>TItle: part because that defines what we are looking for. So based on the example response I switched it to:

"title":(.*)

Now putting in the full example response this is what we get:

"title":"Dredd","type":"movie"}}}

We are closer! Now, we need to figure out why its picking up the rest of the line then we will worry about the "title":" part. In order to figure that out we need to take a closer look at the second part of the regex:

(.*)

Now if you take a look at http://regexlib.com/CheatSheet.aspx it explains in light detail what this means but let me break it down for you.

()
From the cheatsheet:
Logical grouping of part of an expression.


.
From the cheatsheet:
Any character (except \n newline)


*
From the cheatsheet:
0 or more of previous expression.


So based on those three definitions, the second part means in english this: "Match ANY character except a new line. There could be between 0 and infinite number of characters."

Well as you can see from our example "Match ANY character" does not work for us anymore. So looking at the example data we want to stop at the next " (double quote). Looking at the cheatsheet there is no easy way to do with so we need to write it out in "long hand" (meaning write every acceptable character). So for this we could probably assume any letter (a-z) is acceptable, along with the caps version (A-Z), any number (0-9), we also might want to include a few "special" characters like - and : so our second part turns into this:

(0-9a-zA-Z-:*)

Now regex is nice to us to allow us to say: 0-9 instead of having to list it out like 0123456789 and a-z. Note that a-z is NOT the same as A-Z due to the fact that a has a different ASCII value then A and so on. The - and : are not special regex characaters so we just list them. Then we put the * at the end because we don't know how long the movie/show title will be. So our finalized regex is this:

"title":"(0-9a-zA-Z-:*)

Throw that bad bow into the regex tester and hit submit...and WAIT! It doesn't work.... Don't worry, I wasn't misleading you. :D You will notice on the cheatsheet there is a definition for:

[]
From the cheatsheet:
Explicit set of characters to match.


Now, that many not make much sense but basically we can use it to group different characters that it could match. so we modify the regex slight to become:

"title":"([0-9a-zA-Z-:]*)

Now test that and it returns the title! Yay! Notice that the * stayed outside the [] block. That is because we are saying: "There could be 0 to infinity of the characters in the [] block".

So here is our result so far:

"title":"Dredd

Now... if you want the "title":" at the start then great! We are done! but chances are we are not. That is where we need to possibly get DemoPad's help as some regex engines support what I am about to say, some don't. I can't personally test this right now so you might even want to test it and see how it goes...

So we want to dump "title":" from our response...for that we use what is called a Non-Capturing group. That is defined like this:

(?:...)

where the three . is the expression you want to use to help find what you are looking for but not include in your result. So we just need to put the "title":" in that to give us the regex of:

(?:"title":")([0-9a-zA-Z-:]*)

and if the regex engine DemoPad uses supports non-capturing groups then that should return just:

Dredd

and then you are done! Slap that baby into a label and give your remote the "WOW" factor that you want to show off to all your friends! ;)

Hope that helps!

Re: XBMC frodo

Posted: Tue Jan 01, 2013 8:51 pm
by tytherman
that certainly helps, albeit you may as well have said it in Klingon :?

yes it works great in the tester but the xbmc sample is a little more complex, for one you first need to ask which Player is active - music is 0 and video 1, then you need to ask various questions "title" is one of them. I just dont understand why when it was so simple in http they removed it?

in the device I have amended the Getcurrentlyplaying command to reflect the text I put in my previous post, ive also changed the port to the json port 9090 - right or wrong? Also is the username and password for xbmc not required?

Re: XBMC frodo

Posted: Tue Jan 01, 2013 8:57 pm
by tytherman
ps I do appreciate your help on this!

by the way with both

(?:"title":")([0-9a-zA-Z-:]*) and the first one the response I get in the tester is

Match $1
"title":"Dredd Dredd

Re: XBMC frodo

Posted: Tue Jan 01, 2013 9:15 pm
by bob3695
haha sorry, regex is a bit technical so it takes some explaining to get out what is needed :)

As for the complexity of the setup that is needed, yes, it is more complex but not much more complex... for example (DemoPad - correct me if I am wrong here!) multiple regex 2-way feedback items can be triggered from the same response (if I am incorrect then this does get a bit more complex). So what you would do is setup one that looks at the "type" from your example response and that sets a flag, say "IsMovie". In theory you would actually need two regex...one that triggers on "type":"movie" and one that triggers on "type":"tvshow". That flag would be used to make different labels on the page show or hide. As for pulling the other info just put the reg ex in for each and set a dynamic label with each so you would have a "Title" dynamic label, "Show Title" dynamic label, etc. and have the labels on the page mapped to them. The example regex will match on an empty value like in the showtitle in your example. If you have it all wired up correctly then the correct labels will show/hide based on if it is a movie or a tv show and all labels should be populated correctly.

As for the port - that should be correct if thats what you used in Hercules.

Yeah, I am not sure about that but the (?:...) syntax has worked for me in previous programming projects (.NET mostly). I do see that it is not working in the regex tester...so it might just not support it. Again - that may or may not work with DemoPad, we need DemoPad to weigh in or I need to get off my butt and test it :D If it doesn't work I am afraid we will have to take a step back and re-think the strategy of dumping that part. I will defer to the developer of this particular project as I am very interested in knowing if this method works and also what we would need to do if it doesn't.

Thanks

Re: XBMC frodo

Posted: Wed Jan 02, 2013 1:26 pm
by bob3695
After reading through the two-way feedback post in the tutorial section I have come to find that I was slightly incorrect. DemoPad takes the first grouped match so your reflex would be:

"title":"([a-zA-Z0-9:-]*)

And DemoPad should take care of the rest!

Re: XBMC frodo

Posted: Wed Jan 02, 2013 2:17 pm
by tytherman
Ok thanks I'll give that a go.

Re: XBMC frodo

Posted: Wed Jan 02, 2013 4:09 pm
by trevorst
@bob3695
That is a fantastic post on setting up a regex feedback, it will help a lot of people in the future.
Thank You for taking the time.

Re: XBMC frodo

Posted: Wed Jan 02, 2013 4:31 pm
by bob3695
Thanks! I'm glad it was helpful!

Re: XBMC frodo

Posted: Wed Jan 02, 2013 7:37 pm
by bob3695
Another thing to note is I neglected the "space characters" which is handled by \s so new regex:

"title":"([A-Za-z0-9\s:-]*)

Re: XBMC frodo

Posted: Wed May 22, 2013 7:07 am
by ChrisB75
I've been diving into the world of jsonrpc, feedback and regex trying to pull info from my raspberry pi running xbmc with varying amounts of success :? and hoping someone can help. I started by using the Demopad XBMC download but it seems this was written "pre Frodo" and that the commands changed following xbmc dropping HTTP api in favour of json rpi. I think!? I've been using both Hercules and the regex tester website and managed to send an initial request for currently playing info in Hercules using the following whilst connected to xbmcipaddress on port 9090;

/jsonrpc?request={"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "duration", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 0 }, "id": "AudioGetItem"}$0D$0A

which works and returns;

{"id":"AudioGetItem","jsonrpc":"2.0","result":{"item":{"album":"Collected","artist":["Massive Attack"],"duration":340,"fanart":"","file":"/var/media/08DA-91F3/Music/Massive Attack/Collected/15 False Flags.m4a","id":340,"label":"False Flags","thumbnail":"image://%2fvar%2fmedia%2f08DA-91F3%2fMusic%2fMassive%20Attack%2fCollected%2ffolder.jpg/","title":"False Flags","type":"song"}}}
from which the regex

"title":"([A-Za-z0-9\s:-]*)

produces

Match $1
"title":"Teardrop Teardrop

I can't find a way to just leave Teardrop so any help with that too would be appreciated :) I tried the suggestion including a question mark but it still produced the same results (sorry, I forget the exact use of the ?)

So, I have set up a device called XBMCNEW with the my xbmc ip address on port 9090 and set up feedback on this to send the result of "title":"([A-Za-z0-9\s:-]*) to a label called TrackTitle. I then have an image on a page with DynamicLabel for TrackText. I have a button that sends the following command to device XBMC, which when I put the equivalent (xbmcipaddress:80/jsonrpc?request={"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "duration", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 0 }, "id": "AudioGetItem"}$0D$0A) into a web browser returns the information as shown further above - I used port 80 doing this as the xbmc jsonrpc wiki said to);
{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "duration", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 0 }, "id": "AudioGetItem"}$0D$0A

However, finally getting to the point :lol: , the dynamic label image remains blank!? :roll:

I have tried changing all sorts of things such as sending data to a webpage using

xbmcipaddress:80/jsonrpc?request={"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "duration", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 0 }, "id": "AudioGetItem"}$0D$0A

And changing the port to 80 and maintaining an active connection and not maintaining an active connection and adding /jsonrpc?request to the end of the xbmc ip address in the device and so many other things I can't even remember!? :cry:

If anyone can understand my ramblings and has a straight forwards "just do this......" suggestion it will save me yet more confusion and I will be extremely grateful :) Cheers

Re: XBMC frodo

Posted: Wed May 22, 2013 7:57 am
by ChrisB75
I forgot to say that I have done all the appropriate settings in XBMC for udnp and control by http :)

Re: XBMC frodo

Posted: Sun Aug 18, 2013 4:33 pm
by frcor
Hi ChrisB75,
I am exactly at the same point as you. Everything works "outside" Demopad meaning I can send JSON command to my xbmc server through Hercules, got the answer back from xbmc, use Regex to extract the title but the dynamic label just does not work !!.
I have spent 2 entire day trying to find what is work with my setting but if anyone has XBMC Frodo feedback working with DemoPad please help :).
I do not want feedback through the HTTP API as it is not supported anymore in XBMC Frodo.

By the way I am an iRule user and the two ways feedbacks work GREAT with XBMC Frodo. I would like to move to Demopad but feedback s are very important for what I want to do.

Thank you all for your help.