Author Topic: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012  (Read 25836 times)

0 Members and 2 Guests are viewing this topic.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #15 on: January 09, 2013, 10:05:38 AM »
I need to wait until I get home to find a file that has multiple languages in it.  What exactly are you trying to read?  The number of languages?  The current index?

This is return the current index:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="885" name="get stream index" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>XJson.Raw</cmdType>
    <cmdString>Player.GetProperties&amp;&amp;"playerid":1,"properties":["currentaudiostream"]</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>XJson.ParseTokens</cmdType>
    <cmdString>{currentaudiostream.index}</cmdString>
    <cmdRepeat>0</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <cmdString>{LastResult}&amp;&amp;5000</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
</command>

fishware

  • Jr. Member
  • **
  • Posts: 44
  • Karma: 1
    • View Profile
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #16 on: January 09, 2013, 10:19:18 AM »
I want to read the current Index.

For future projects it would be nice to read all result items.
So I can specify commands like "switch to english" or "switch to france", if the specified language available.

Thanks Chris

claymic

  • $upporter
  • Sr. Member
  • *****
  • Posts: 152
  • Karma: 0
    • View Profile
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #17 on: January 09, 2013, 07:47:50 PM »
You can read the language too
Code: [Select]
<cmdString>{currentaudiostream.language}</cmdString>This will give to you something like
en - for english
por - for portuguese
If you call this:
Code: [Select]
<cmdString>Player.GetProperties&amp;&amp;"playerid":1,"properties":["audiostreams"]</cmdString>You will recive a array with the audios of the file, samething for "subtitle".
I dont test the Json in VoxCommando yet, so i dont know how to get the values of the array, James will tell you if its possible, maybe with something like this (in the json parse)
Code: [Select]
<cmdString>{audiostreams[0].language}</cmdString>Congratulations James ;D
« Last Edit: January 09, 2013, 08:46:37 PM by claymic »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #18 on: January 10, 2013, 01:20:08 PM »
Thanks Clayton.  You are on the right track for sure.

Here are a couple of sample commands that will give you an idea of what you can do.  If you need explanation just let me know.

By the way, the parse command is one that we will experiment with and possibly, we will decide that there is a better way to do it.  Once you have played with it enough to understand how it works, if you have suggestions, please share them.

claymic

  • $upporter
  • Sr. Member
  • *****
  • Posts: 152
  • Karma: 0
    • View Profile
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #19 on: January 10, 2013, 02:06:03 PM »
James, i have to install the Vox in my htpc again.
Do you think its possible insert filters in the request ?
See in this video:

Any request in my app its made with a filter field, if you put this in vox will be a very good thing to play around.
Lets say we wanna play only the unwatched episodes  for a tvshow, we just need to say the name of the tvshow and then your script will make the json request and insert the episodes in a video playlist, this will work for movies (like genre), tvshows and musics (album, artist, genre,...). Everything now can be found with the filters, its cool and we will not have to create any playlist. We can use operators too, like "and" "or".
I can send all the code for you, but its in .js. If you want to make the script to work with this let me know, maybe i can learn a little more working with you  ;D
Clayton
p.s little preview of the tvshow wall in my app 8)

claymic

  • $upporter
  • Sr. Member
  • *****
  • Posts: 152
  • Karma: 0
    • View Profile
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #20 on: January 10, 2013, 02:22:07 PM »
Ok
I just see the code. Its really cool man. Very nice work again. I will play with this a little more.
What is the {LastResult} ? this is the data that you get from the json parse in this case? So, every time that a make a request or a parse i can access the data with the {LastResult}?
If possible can you describe each step ? I am a little lost with some values like
{Var.numstreams} its the length of the variable numstreams, but i dont know how to set the variable for get not only the length, will be nice if you explain each step for us (me :biglaugh);
Clayton

claymic

  • $upporter
  • Sr. Member
  • *****
  • Posts: 152
  • Karma: 0
    • View Profile
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #21 on: January 10, 2013, 03:45:44 PM »
Ok, tested a little more. Since we can manipulate the params, we can insert filters too, or not ?
Clayton

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #22 on: January 10, 2013, 04:59:16 PM »
Ok, tested a little more. Since we can manipulate the params, we can insert filters too, or not ?
Clayton

Yes.  You can send any json command that XBMC will understand.  We can send a sequence of commands such as playlist.clear, playlist.add (type, filter, etc), playlist play, etc.

If you have sample commands with filters please send them to me.  I am sure it will be helpful.  It does not matter if it is in javascript, I just need to look at the json command strings.

claymic

  • $upporter
  • Sr. Member
  • *****
  • Posts: 152
  • Karma: 0
    • View Profile
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #23 on: January 10, 2013, 05:15:04 PM »
James, i will post the function here, its big but you will understand, but i will make the request in one line and post later.
I made this function to request tvshows. Its big because i am manipulating 3 filters and 2 operators. this function first  analyze the 2º filter, the analyze the 2º, use the operator to determine if its true or not, and then compare the result with the first filter. I will try to explain this better later.
I will mount the request in a simple line with some examples, i just cant make this right now, sorry.
See the function:
Code: [Select]
self.getTvshowFilter2 = function(type,linkOperator1,linkOperator2,baseJoin,sortorder,sortmethod,field1,operator1,value1,field2,operator2,value2,field3,operator3,
  value3,limits){
      var linkoperator1  = linkOperator1;
      var linkoperator2  = linkOperator2;
      if (limits) {
         var limits = parseInt(limits);
         var params = {
            sort: {"order": sortorder, "method": sortmethod},
            properties: ["title","art","episode","watchedepisodes","year","imdbnumber","playcount","plot"],
            filter: {},
            limits: {"end": limits}
         };
      } else {
        var params = {
           sort: {"order": sortorder, "method": sortmethod},
           properties: ["title","art","episode","watchedepisodes","year","imdbnumber","playcount","plot"],
           filter: {}   
        };
      }
      if (type=="1"){
         params.filter = {field: field1, operator: operator1, value: value1};
      }
      if (type == "2"){
         params.filter[linkoperator1] = [
            {field: field1, operator: operator1, value: value1},
            {field: field2, operator: operator2, value: value2}
         ];
      } else if(type == "3"){
        var filteroperator2 = {};
        filteroperator2[linkoperator2] = [
            {field: field2, operator: operator2, value: value2},
            {field: field3, operator: operator3, value: value3},
         ];
         params.filter[linkoperator1] =[
           filteroperator2,
           {field: field1, operator: operator1, value: value1}
         ]
      } 
      self.rpc("VideoLibrary.GetTVShows", params, function(data) {
      // CF.logObject(data);
          CF.listRemove("l"+baseJoin);
          var arrayTvShowFilter = [];
          for (i=0;i<data.result.limits.end;i++){
             var tvshowid = data.result.tvshows[i].tvshowid;
             var showtitle = decode_utf8(data.result.tvshows[i].title);
             var plot = decode_utf8(data.result.tvshows[i].plot);
             var banner = self.URL + "vfs/" + data.result.tvshows[i].art.banner;
             var episode = data.result.tvshows[i].episode;
             var watchedepisodes = data.result.tvshows[i].watchedepisodes;
             var unwatched = episode - watchedepisodes;
             var unwatched = "Não Assistidos: "+ unwatched;
             var playcount = data.result.tvshows[i].playcount;
             var playcount = (playcount > 0) ? 1:0;
             var year = "("+data.result.tvshows[i].year+")";
             var imdbnumber = data.result.tvshows[i].imdbnumber;
             arrayTvShowFilter.push({
                s21 : tvshowid,
                s22 : showtitle,
                s23 : banner,
                s24 : year,
                s25 : unwatched,
                d21: {
       tokens: {
       "[tvshowid]": tvshowid,
                     "[imdbnumber]": imdbnumber,
                     "[plot]": plot,
                   }
                },
                d22: playcount
            });
          }
          CF.listAdd("l"+baseJoin,arrayTvShowFilter)
          if (baseJoin  == XBMCMacMini.joinTvShowWallTopList){
             self.arrayTvShowWall = [];
             self.arrayTvShowWall = arrayTvShowFilter;
             self.buildTvShowWall(XBMCMacMini.joinTvShowWall,2);
          }
      })
  }

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #24 on: January 10, 2013, 05:17:48 PM »
Ok
I just see the code. Its really cool man. Very nice work again. I will play with this a little more.
What is the {LastResult} ? this is the data that you get from the json parse in this case? So, every time that a make a request or a parse i can access the data with the {LastResult}?
If possible can you describe each step ? I am a little lost with some values like
{Var.numstreams} its the length of the variable numstreams, but i dont know how to set the variable for get not only the length, will be nice if you explain each step for us (me :biglaugh);
Clayton

{LastResult} is like a variable that gets updated any time an action produces a result.  Some actions (for example OSD.Show) do not change the value of {lastresult}

When we send the first action:
Code: [Select]
<action actiontype="XJson.Raw" repeat="1" logic="False"><paramstring>Player.GetProperties&amp;&amp;"playerid":1,"properties":["audiostreams"]</paramstring></action>
Then {LastResult} will be equal to whatever XBMC returns.  For example is I have two audio streams it might be somethign like this:
Code: [Select]
{
  "audiostreams": [
    {
      "index": 0,
      "language": "fre",
      "name": "DTS 5.1 - DTS 5.1"
    },
    {
      "index": 1,
      "language": "eng",
      "name": "DTS 5.1 - DTS 5.1"
    }
  ]
}

When we call XJson.ParseTokens, LastResult result will be replaced with a new value.  Parse tokens modifies the input string and replaces  tokens such as {audiostreams[0].language} based on the the last json response that was received from XBMC.  Whatever string we get is now stored in {LastResult}.  In this case the token is {audiostreams[
  • ]} which returns the number of items in the JSON array "audiostreams"


Next I am creating a new variable to store a value in.  When I call
Code: [Select]
<action actiontype="Results.SetVar" repeat="1" logic="False"><paramstring>numstreams&amp;&amp;{LastResult}</paramstring></action>
I am creating a variable called "numstreams" and putting the value of {LastResult} into it.  Later I can read this variable using {var.numstreams}

In the case of the command named: "XJson audio stream languages parse and logic" I am then using this variable with Logic Blocks, to decide how to parse the JSON data that was returned by calling Player.GetProperties   "playerid":1,"properties":["audiostreams"]

if there is only one stream, I show it by parsing tokens again, this time I use the format:
Code: [Select]
Stream 0:{audiostreams[0].language}
and if there are 2 streams I show the data for both of them by using this format:
Code: [Select]
Stream 0:{audiostreams[0].language}{CR}Stream 1:{audiostreams[1].language}

claymic

  • $upporter
  • Sr. Member
  • *****
  • Posts: 152
  • Karma: 0
    • View Profile
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #25 on: January 10, 2013, 05:25:37 PM »
How, great. Very thanks for take time to explain this. I will have some fun making codes for Xbmc with Vox now ;D
Thanks again.
Clayton

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #26 on: January 10, 2013, 05:35:55 PM »
I think we have a bit of work to do still.

We can use a filter with GetTVShows, but this does not really allow us to play all the TVShows...

It is for this reason that I mostly am planning to use Smart Playlists.

But maybe we can do something with it still.  It will require some thought, and a lot of work I think, but we will figure it out!

claymic

  • $upporter
  • Sr. Member
  • *****
  • Posts: 152
  • Karma: 0
    • View Profile
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #27 on: January 10, 2013, 05:39:56 PM »
Jame, my intention its use your addon to insert the files in the playlist, its very easy to make. Maybe will be better pass the params directly for the addon, and then make the json request with this we can easily insert the files in a playlist ;D

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #28 on: January 10, 2013, 05:59:17 PM »
Yes, it should be possible to request a list of songs using a filter and then create a playlist.  My only concern is that this is very inneffecient because we need to loop though all the results and add each song to the playlist, one by one, and each time we do this we need to create a new JSON command that we send accross the network.  The old http api was so much better because we could just send an sql statement.  It was fantastic.  Why they had to change this I will never understand.  :(

I am wondering if it makes more sense for us to use the voxtools plugin to do this.  At least that way we are not creating a huge amount of network traffic for nothing.  the python script could do it all internally.

If you just want to request music by id (album, artist, song) here are some commands that are working for me:

claymic

  • $upporter
  • Sr. Member
  • *****
  • Posts: 152
  • Karma: 0
    • View Profile
Re: XBMC JSON: for pre-Frodo nightlies after Oct. 9th 2012
« Reply #29 on: January 10, 2013, 06:30:26 PM »
Yes, the script its a lot of better to manipulate and create playllists on the fly.
But we can use filters to get cool requests.
Code: [Select]
{"jsonrpc": "2.0", "method": "videoLibrary.Gettvshows", "params":
    { "sort": {"order": "descending", "method": "lastplayed"},
    "filter": {"field": "inprogress", "operator": "true", "value": ""},
    "proerties":["title"]  }, "id": 1}
The filter above give us the lastplayed tvshow if this tvshow have at least one episode unwatched. Its cool.
Lets  insert another filter:
Code: [Select]
{"jsonrpc": "2.0", "method": "videoLibrary.Gettvshows", "params":
    { "sort": {"order": "descending", "method": "lastplayed"},
   "filter": {"and":[{"field": "inprogress", "operator": "true", "value": ""},{"field": "title", "operator": "startwith", "value": "a"}}],
   "proerties"["title"]  }, "id": 1}

Now we get the last tvshow played with at least one episode unwatched and the title start with the char "a", its just a exemple.
We can create many filters we want, what we will do with the result its another history ;D
« Last Edit: January 10, 2013, 06:40:55 PM by claymic »