JSON-RPC API/Examples: Difference between revisions
Jump to navigation
Jump to search
m (Bot: Automated text replacement (-class="wikitable" +class="prettytable" & -Available Tags +Available tags & -<source +<syntaxhighlight & -</source> +</syntaxhighlight>)) |
m (Bot: automated adding of 'enclose="div"' to syntaxhighlight) |
||
Line 6: | Line 6: | ||
=== Introspect === | === Introspect === | ||
If you require more detailed information about an API method use: | If you require more detailed information about an API method use: | ||
<syntaxhighlight 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 } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 12: | Line 12: | ||
=== 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 XBMC will only work if that player is currently in use. | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript" enclose="div"> | ||
{"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1} | {"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1} | ||
</syntaxhighlight><br /> | </syntaxhighlight><br /> | ||
<syntaxhighlight 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" } ]} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 21: | Line 21: | ||
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: | ||
<syntaxhighlight 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"} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
or | or | ||
<syntaxhighlight 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"} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 32: | Line 32: | ||
=== Player play/pause === | === Player play/pause === | ||
<syntaxhighlight 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} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 38: | Line 38: | ||
=== Query the libraries === | === Query the libraries === | ||
Artists | Artists | ||
<syntaxhighlight 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} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Albums | Albums | ||
<syntaxhighlight 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"} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Songs | Songs | ||
<syntaxhighlight 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"} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Movies | Movies | ||
<syntaxhighlight 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"} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
TV Shows | TV Shows | ||
<syntaxhighlight 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"} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Music Videos | Music Videos | ||
<syntaxhighlight 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"} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Audio Playlist | Audio Playlist | ||
<syntaxhighlight 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} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Video Playlist | Video Playlist | ||
<syntaxhighlight 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} | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 06:44, 14 March 2014
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 XBMC 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}
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"}
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}