Kodi Community Forum

Full Version: Get type from the JSON feed
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello All,

I'm currently developing my own Home Dashboard. One of the things that I am working on doing is you can create pages for the rooms in our home and view whats going on in each room. One of the items I'd like to display is if there is currently a Kodi setup in the room I'd like to display what is currently playing on that device. I am currently able to pull video information using the following JSON Query.

Code:
{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "genre", "year", "rating", "playcount", "fanart", "director", "trailer", "tagline", "plot", "plotoutline", "originaltitle", "lastplayed", "writer", "studio", "mpaa", "cast", "country", "imdbnumber", "premiered", "runtime", "streamdetails", "votes", "thumbnail", "tag", "art", "sorttitle", "dateadded", "season", "episode"], "playerid": 1 }, "id": "VideoGetItem"}

I'm able to pull what I need. What I want to do however is based off Type, which seems to be available from http://kodi.wiki/view/JSON-RPC_API/v6#List.Item.Base . However I can't seem to figure out how to pull that bit of information. I'd like to use it in my PHP code so that based on what this returns I can format appropriately for Music/Movie/TV Show. I've tried changing the formatting a few times, however I believe I may be missing something.

I've tried the following:
Code:
{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["type"], "playerid": 1}, "id": "List.Item.Base"} and when I go to it in the URL I get the following response:
{"error":{"code":-32602,"data":{"method":"Player.GetItem","stack":{"message":"array element at index 0 does not match","name":"Item.Fields.Base","property":{"message":"Received value does not match any of the defined enum values","type":"string"},"type":"array"}},"message":"Invalid params."},"id":"List.Item.Base","jsonrpc":"2.0"}

Any help in pointing me to what I am missing here would be greatly appreciated Smile.
Player.GetItem does not take any parameter "type".
parameters are listed in List.Fields.All

What returns is listed in List.Item.... to which a type is one of the returned items...


So do something like this, note no property parameter "type" or otherwise:
{"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":0,"properties":[]},"id":54}

and you will get back something like this which includes a "type" property

{
"item": {
"label": "videoplayback",
"type": "episode"
}
}

an interesting note would be the player id 0, being used to play video.
i find that odd, but i suppose team kodi would tell us its because im using an illegitimate streaming plugin...
I have a bash script that does exactly this!

One of the things I found though is that you cannot count on what the ID for the player is going to be, so the first thing you need to do is get the player ID.

PHP Code:
"jsonrpc""2.0""method""Player.GetActivePlayers""id""mybash"

That will return the ID of the player and also if it is video or audio.

PHP Code:
{"jsonrpc""2.0""method""Player.GetItem""params": { "properties": [ "showtitle""streamdetails","title"], "playerid"'"$PlayerId"' }, "id""VideoGetItem"

Returns a 'type' field which is one of 'episode', 'movie', 'channel' or 'unknown'.

Based on the results of that, you can do a call to get the tv show details, or the movie details. If it's a live TV channel, the name will already have been returned, and if it's 'unknown' (home video or something' then it will already have returned as much as it can about it in the first call.

To get TV show details do

PHP Code:
{"jsonrpc""2.0""method""Player.GetItem""params": { "properties": [ "season""episode"], "playerid"'"$PlayerId"' }, "id""VideoGetItem"

And to get movie details do

PHP Code:
{"jsonrpc""2.0""method""Player.GetItem""params": { "properties": [ "title","runtime"], "playerid"'"$PlayerId"' }, "id""VideoGetItem"

Obviously you can get more info by adding more params to the call, but I just get the movie title and runtime, then display on screen the title and the remaining playing time. The tv-show call should get you the show title, the season and episode info and the episode title.

If it's playing live tv, that first call will return showname and channel name.