JSON-RPC API/Examples: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
(Created page with "{{mininav|Development|JSON-RPC API}} == Examples == These examples take their base from v4. Any that require a higher version will be marked. === Introspect === If y...")
 
mNo edit summary
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{JSON-RPC_API_nav}}
{{mininav|[[Development]]|[[JSON-RPC API]]}}
{{mininav|[[Development]]|[[JSON-RPC API]]}}


Line 6: Line 7:
=== Introspect ===
=== Introspect ===
If you require more detailed information about an API method use:
If you require more detailed information about an API method use:
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{ "jsonrpc": "2.0", "method": "JSONRPC.Introspect", "params": { "filter": { "id": "AudioLibrary.GetAlbums", "type": "method" } }, "id": 1 }
{ "jsonrpc": "2.0", "method": "JSONRPC.Introspect", "params": { "filter": { "id": "AudioLibrary.GetAlbums", "type": "method" } }, "id": 1 }
</source>
</syntaxhighlight>
"AudioLibrary.GetAlbums" being the method in this example.
"AudioLibrary.GetAlbums" being the method in this example.
=== What is playing? ===
=== What is playing? ===
Commands to control the players in XBMC will only work if that player is currently in use.
Commands to control the players in Kodi will only work if that player is currently in use.
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1}
{"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1}
</source><br />
</syntaxhighlight><br />
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"id": 1, "jsonrpc": "2.0", "result": [ { "playerid": 0, "type": "audio" } ]}
{"id": 1, "jsonrpc": "2.0", "result": [ { "playerid": 0, "type": "audio" } ]}
</source>
</syntaxhighlight>
In the above we can see that the audio player is active. It is possible for more than one player to be active: picture and audio.
In the above we can see that the audio player is active. It is possible for more than one player to be active: picture and audio.


Now we know which player is active we can query the current item with:
Now we know which player is active we can query the current item with:
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "duration", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 0 }, "id": "AudioGetItem"}
{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "duration", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 0 }, "id": "AudioGetItem"}
</source>
</syntaxhighlight>
or
or
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "season", "episode", "duration", "showtitle", "tvshowid", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 1 }, "id": "VideoGetItem"}
{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "season", "episode", "duration", "showtitle", "tvshowid", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 1 }, "id": "VideoGetItem"}
</source>
</syntaxhighlight>


GetItem will ignore any properties that don't make sense for the specific player.
GetItem will ignore any properties that don't make sense for the specific player.


=== Player play/pause ===
=== Player play/pause ===
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "Player.PlayPause", "params": { "playerid": 0 }, "id": 1}
{"jsonrpc": "2.0", "method": "Player.PlayPause", "params": { "playerid": 0 }, "id": 1}
</source>
</syntaxhighlight>
 
=== Get Properties ===
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["volume"]}, "id": 1}
</syntaxhighlight>


=== Query the libraries ===
=== Query the libraries ===
Artists
Artists
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "AudioLibrary.GetArtists", "params": { "limits": { "start" : 0, "end": 75 }, "properties": [ "thumbnail", "fanart", "born", "formed", "died", "disbanded", "yearsactive", "mood", "style", "genre" ], "sort": { "order": "ascending", "method": "artist", "ignorearticle": true } }, "id": 1}
{"jsonrpc": "2.0", "method": "AudioLibrary.GetArtists", "params": { "limits": { "start" : 0, "end": 75 }, "properties": [ "thumbnail", "fanart", "born", "formed", "died", "disbanded", "yearsactive", "mood", "style", "genre" ], "sort": { "order": "ascending", "method": "artist", "ignorearticle": true } }, "id": 1}
</source>
</syntaxhighlight>
Albums
Albums
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": { "limits": { "start" : 0, "end": 50 }, "properties": ["playcount", "artist", "genre", "rating", "thumbnail", "year", "mood", "style"], "sort": { "order": "ascending", "method": "album", "ignorearticle": true } }, "id": "libAlbums"}
{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": { "limits": { "start" : 0, "end": 50 }, "properties": ["playcount", "artist", "genre", "rating", "thumbnail", "year", "mood", "style"], "sort": { "order": "ascending", "method": "album", "ignorearticle": true } }, "id": "libAlbums"}
</source>
</syntaxhighlight>
Songs
Songs
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "AudioLibrary.GetSongs", "params": { "limits": { "start" : 0, "end": 25 }, "properties": [ "artist", "duration", "album", "track" ], "sort": { "order": "ascending", "method": "track", "ignorearticle": true } }, "id": "libSongs"}
{"jsonrpc": "2.0", "method": "AudioLibrary.GetSongs", "params": { "limits": { "start" : 0, "end": 25 }, "properties": [ "artist", "duration", "album", "track" ], "sort": { "order": "ascending", "method": "track", "ignorearticle": true } }, "id": "libSongs"}
</source>
</syntaxhighlight>
Movies
Movies
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "filter": {"field": "playcount", "operator": "is", "value": "0"}, "limits": { "start" : 0, "end": 75 }, "properties" : ["art", "rating", "thumbnail", "playcount", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMovies"}
{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "filter": {"field": "playcount", "operator": "is", "value": "0"}, "limits": { "start" : 0, "end": 75 }, "properties" : ["art", "rating", "thumbnail", "playcount", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMovies"}
</source>
</syntaxhighlight>
 
Movie With Multiple Filters
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "properties": [ "title", "lastplayed", "studio", "cast", "plot", "writer", "director", "fanart", "runtime", "mpaa", "thumbnail", "file","year", "genre", "tag", "trailer" ], "filter": { "or": [ { "field": "genre", "operator": "contains", "value": [ "Film-Noir" ] }, { "field": "tag", "operator": "contains", "value": [ "classic noir", "film noir", "french noir", "brit noir" ] } ] } }, "id": 1 }
</syntaxhighlight>
 
TV Shows
TV Shows
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"field": "playcount", "operator": "is", "value": "0"}, "limits": { "start" : 0, "end": 75 }, "properties": ["art", "genre", "plot", "title", "originaltitle", "year", "rating", "thumbnail", "playcount", "file", "fanart"], "sort": { "order": "ascending", "method": "label" } }, "id": "libTvShows"}
{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"field": "playcount", "operator": "is", "value": "0"}, "limits": { "start" : 0, "end": 75 }, "properties": ["art", "genre", "plot", "title", "originaltitle", "year", "rating", "thumbnail", "playcount", "file", "fanart"], "sort": { "order": "ascending", "method": "label" } }, "id": "libTvShows"}
</source>
</syntaxhighlight>
Music Videos
Music Videos
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "properties": [ "title", "thumbnail", "artist", "album", "genre", "lastplayed", "year", "runtime", "fanart", "file", "streamdetails" ], "sort": { "order": "ascending", "method": "artist", "ignorearticle": true } }, "id": "libMusicVideos"}
{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "properties": [ "title", "thumbnail", "artist", "album", "genre", "lastplayed", "year", "runtime", "fanart", "file", "streamdetails" ], "sort": { "order": "ascending", "method": "artist", "ignorearticle": true } }, "id": "libMusicVideos"}
</source>
</syntaxhighlight>
Audio Playlist
Audio Playlist
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": { "properties": ["title", "album", "artist", "duration"], "playlistid": 0 }, "id": 1}
{"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": { "properties": ["title", "album", "artist", "duration"], "playlistid": 0 }, "id": 1}
</source>
</syntaxhighlight>
Video Playlist
Video Playlist
<source lang="javascript">
<syntaxhighlight lang="javascript" enclose="div">
{"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": { "properties": [ "runtime", "showtitle", "season", "title", "artist" ], "playlistid": 1}, "id": 1}
{"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": { "properties": [ "runtime", "showtitle", "season", "title", "artist" ], "playlistid": 1}, "id": 1}
</source>
</syntaxhighlight>
 


[[Category:XBMC Manual]]
[[Category:JSON-RPC]]
[[Category:Development]]

Latest revision as of 23:07, 27 August 2020

JSON-RPC Pages
Main JSON-RPC Page
- v8 (Krypton)
- v10 (Leia)
- v12 (Matrix)
- v13 (Nexus)
- v14 (Omega)
Examples
All JSON-RPC Pages
Home icon grey.png   ▶ Development ▶ JSON-RPC API ▶ Examples

Examples

These examples take their base from v4. Any that require a higher version will be marked.

Introspect

If you require more detailed information about an API method use:

{ "jsonrpc": "2.0", "method": "JSONRPC.Introspect", "params": { "filter": { "id": "AudioLibrary.GetAlbums", "type": "method" } }, "id": 1 }

"AudioLibrary.GetAlbums" being the method in this example.

What is playing?

Commands to control the players in Kodi will only work if that player is currently in use.

{"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1}


{"id": 1, "jsonrpc": "2.0", "result": [ { "playerid": 0, "type": "audio" } ]}

In the above we can see that the audio player is active. It is possible for more than one player to be active: picture and audio.

Now we know which player is active we can query the current item with:

{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "duration", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 0 }, "id": "AudioGetItem"}

or

{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "season", "episode", "duration", "showtitle", "tvshowid", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 1 }, "id": "VideoGetItem"}

GetItem will ignore any properties that don't make sense for the specific player.

Player play/pause

{"jsonrpc": "2.0", "method": "Player.PlayPause", "params": { "playerid": 0 }, "id": 1}

Get Properties

{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["volume"]}, "id": 1}

Query the libraries

Artists

{"jsonrpc": "2.0", "method": "AudioLibrary.GetArtists", "params": { "limits": { "start" : 0, "end": 75 }, "properties": [ "thumbnail", "fanart", "born", "formed", "died", "disbanded", "yearsactive", "mood", "style", "genre" ], "sort": { "order": "ascending", "method": "artist", "ignorearticle": true } }, "id": 1}

Albums

{"jsonrpc": "2.0", "method": "AudioLibrary.GetAlbums", "params": { "limits": { "start" : 0, "end": 50 }, "properties": ["playcount", "artist", "genre", "rating", "thumbnail", "year", "mood", "style"], "sort": { "order": "ascending", "method": "album", "ignorearticle": true } }, "id": "libAlbums"}

Songs

{"jsonrpc": "2.0", "method": "AudioLibrary.GetSongs", "params": { "limits": { "start" : 0, "end": 25 }, "properties": [ "artist", "duration", "album", "track" ], "sort": { "order": "ascending", "method": "track", "ignorearticle": true } }, "id": "libSongs"}

Movies

{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "filter": {"field": "playcount", "operator": "is", "value": "0"}, "limits": { "start" : 0, "end": 75 }, "properties" : ["art", "rating", "thumbnail", "playcount", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libMovies"}

Movie With Multiple Filters

{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": { "properties": [ "title", "lastplayed", "studio", "cast", "plot", "writer", "director", "fanart", "runtime", "mpaa", "thumbnail", "file","year", "genre", "tag", "trailer" ], "filter": { "or": [ { "field": "genre", "operator": "contains", "value": [ "Film-Noir" ] }, { "field": "tag", "operator": "contains", "value": [ "classic noir", "film noir", "french noir", "brit noir" ] } ] } }, "id": 1 }

TV Shows

{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"field": "playcount", "operator": "is", "value": "0"}, "limits": { "start" : 0, "end": 75 }, "properties": ["art", "genre", "plot", "title", "originaltitle", "year", "rating", "thumbnail", "playcount", "file", "fanart"], "sort": { "order": "ascending", "method": "label" } }, "id": "libTvShows"}

Music Videos

{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": { "properties": [ "title", "thumbnail", "artist", "album", "genre", "lastplayed", "year", "runtime", "fanart", "file", "streamdetails" ], "sort": { "order": "ascending", "method": "artist", "ignorearticle": true } }, "id": "libMusicVideos"}

Audio Playlist

{"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": { "properties": ["title", "album", "artist", "duration"], "playlistid": 0 }, "id": 1}

Video Playlist

{"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": { "properties": [ "runtime", "showtitle", "season", "title", "artist" ], "playlistid": 1}, "id": 1}