Kodi Community Forum
Working JSON RPC API Examples - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Kodi Application (https://forum.kodi.tv/forumdisplay.php?fid=93)
+---- Forum: JSON-RPC (https://forum.kodi.tv/forumdisplay.php?fid=174)
+---- Thread: Working JSON RPC API Examples (/showthread.php?tid=157996)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16


RE: Working JSON RPC API Examples - danofun - 2019-03-08

@nissse Any luck finding a solution to the PVR Player.Open issue?  I'm able to accomplish the task via curl but unsuccessful via Javascript.
Code:
curl -s --data-binary '{"jsonrpc": "2.0", "method": "Player.Open","params":{"item":{"channelid":5}},"id": 1}' -H 'content-type: application/json;' http://$IP:8080/jsonrpc



RE: Working JSON RPC API Examples - redespace - 2019-04-03

Hi Everyone,

Hopefully some of you clever guys can help me out. I have Kodi running on a Rpi (Libreelec) and what I had a script running that checked if there was any video playing on Kodi.
My script is:


Code:
 playing=1
 myvar=""
 myvar=$(curl -s -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params":{"properties": ["tvshowid"], "playerid": 1}, "id": "VideoGetItem"}' http://[username]:[pass]@127.0.0.1:58080/jsonrpc)
 case "$myvar" in
 *unknown*) playing=0 ;;
 *       )  ;;
 esac
 while $playing == 1 (wiki)
 do
        myvar=""
        myvar=$(curl -s -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params":{"properties": ["tvshowid"], "playerid": 1}, "id": "VideoGetItem"}' http://[username]:[pass]@127.0.0.1:58080/jsonrpc);
        case "$myvar" in
                *unknown*) playing=0 ;;
                *       )  ;;
         esac
         sleep 900
 done

The problem I am having is that since LEIA came out, this is not working anymore. The variable is returning:
Code:
MyPI:~/.config # $myvar
-sh: <html><head><title>File: not found

Any ideas what could be the problem?


RE: Working JSON RPC API Examples - trogggy - 2019-04-03

(2019-04-03, 12:53)redespace Wrote:  I had a script running that checked if there was any video playing on Kodi.
Any reason not to use python?
Quote:import xbmc
if xbmc.Player().isPlayingVideo():
    do summat



RE: Working JSON RPC API Examples - redespace - 2019-04-03

(2019-04-03, 13:12)trogggy Wrote:
(2019-04-03, 12:53)redespace Wrote:  I had a script running that checked if there was any video playing on Kodi.
Any reason not to use python?
Quote:import xbmc
if xbmc.Player().isPlayingVideo():
    do summat
@trogggy Didn't know that was an option Smile I tried it, but unfortunately failed:
Quote:ImportError: No module named xbmc
It seems from Kodi's forum post (https://forum.kodi.tv/showthread.php?tid=326044) that you cannot use XBMC's modules from outside Kodi. Do you have a way how to import it?


RE: Working JSON RPC API Examples - trogggy - 2019-04-03

No, you're correct - you have to run it from kodi.  You could always do that using kodi-send, but I don't know whether that's your best option.  It was just a thought / alternative.


RE: Working JSON RPC API Examples - HTGeek - 2019-04-06

(2019-04-03, 12:53)redespace Wrote: Hi Everyone,

Hopefully some of you clever guys can help me out. I have Kodi running on a Rpi (Libreelec) and what I had a script running that checked if there was any video playing on Kodi.
My script is:


Code:
 playing=1
 myvar=""
 myvar=$(curl -s -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params":{"properties": ["tvshowid"], "playerid": 1}, "id": "VideoGetItem"}' http://[username]:[pass]@127.0.0.1:58080/jsonrpc)
 case "$myvar" in
 *unknown*) playing=0 ;;
 *       )  ;;
 esac
 while $playing == 1 (wiki)
 do
        myvar=""
        myvar=$(curl -s -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params":{"properties": ["tvshowid"], "playerid": 1}, "id": "VideoGetItem"}' http://[username]:[pass]@127.0.0.1:58080/jsonrpc);
        case "$myvar" in
                *unknown*) playing=0 ;;
                *       )  ;;
         esac
         sleep 900
 done

The problem I am having is that since LEIA came out, this is not working anymore. The variable is returning:
Code:
MyPI:~/.config # $myvar
-sh: <html><head><title>File: not found

Any ideas what could be the problem?

Have you tried:

1. Put the http address in front of -d (i.e...

Code:
myvar=$(curl -s -H 'Content-Type: application/json' http://[username]:[pass]@127.0.0.1:58080/jsonrpc -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params":{"properties": ["tvshowid"], "playerid": 1}, "id": "VideoGetItem"}' )

and/or

2. -X in curl, such as:

Code:
 myvar=$(curl -s -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params":{"properties": ["tvshowid"], "playerid": 1}, "id": "VideoGetItem"}' http://[username]:[pass]@127.0.0.1:58080/jsonrpc)

I'm using Ubuntu server, which presumes GET unless you force it to POST method via -X POST


RE: Working JSON RPC API Examples - lysyi - 2019-08-13

Hi,
How to search in plugin.video.youtube?
Sorry for the Google translation.


RE: Working JSON RPC API Examples - HTGeek - 2019-08-13

(2019-08-13, 06:36)lysyi Wrote: Hi,
How to search in plugin.video.youtube?
Sorry for the Google translation.

3 questions:

1. What are you trying to accomplish?
2. Have you read the Kodi API Wiki?
3. What version number (major.minor) of Kodi are you using?


RE: Working JSON RPC API Examples - lysyi - 2019-08-13

(2019-08-13, 21:31)HTGeek Wrote:
(2019-08-13, 06:36)lysyi Wrote: Hi,
How to search in plugin.video.youtube?
Sorry for the Google translation.

3 questions:

1. What are you trying to accomplish?
2. Have you read the Kodi API Wiki?
3. What version number (major.minor) of Kodi are you using? 

1. I want a window with the search result in the YouTube plug-in to appear on request.
2. I read ...
3.18.3
...

So it returns the search results in the response:
json:
{"jsonrpc":"2.0","method":"Files.GetDirectory","params":{"directory": "plugin://plugin.video.youtube/kodion/search/query/?q=1080p" },"id":1}
So the search happens, the request is stored in the YouTube plugin:
json:
{"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"file":"plugin://plugin.video.youtube/kodion/search/query/?q=1080p"}}}
... but I would like just a window with search results.
Sorry for Google translation.


RE: Working JSON RPC API Examples - HTGeek - 2019-08-13

(2019-08-13, 22:00)lysyi Wrote:
(2019-08-13, 21:31)HTGeek Wrote:
(2019-08-13, 06:36)lysyi Wrote: Hi,
How to search in plugin.video.youtube?
Sorry for the Google translation.

3 questions:

1. What are you trying to accomplish?
2. Have you read the Kodi API Wiki?
3. What version number (major.minor) of Kodi are you using?   

1. I want a window with the search result in the YouTube plug-in to appear on request.
2. I read ...
3.18.3
... 

I would think that's a question for YouTube plug-in and not Kodi's API. The Kodi API is regarding the Kodi app itself... the core product. Another possibility is Google's YouTube API... but I suspect that even if you find a way to send a request via the YT API, you would have to find a way to pipe the response to a window in Kodi and then put it in focus (the last part is not hard to do if you can determine the Window ID).

Suggest asking here: https://forum.kodi.tv/showthread.php?tid=267160


RE: Working JSON RPC API Examples - 37KDeep - 2019-10-23

Will someone post a working Curl example to play a Smart playlist?


RE: Working JSON RPC API Examples - 37KDeep - 2019-10-24

I found my answer in another post.

This works for JSON calls to Kodi from within webCoRE to play a Smart playlist.

[{"jsonrpc": "2.0", "id": 0, "method": "Playlist.Clear", "params": {"playlistid": 0}},
{"jsonrpc":"2.0","id":0,"method":"Playlist.Add","params":{"playlistid":0,"item":{"recursive":true, "directory":"special://profile/playlists/music/zzzz.xsp"}}},
{"jsonrpc":"2.0","id":0,"method":"Player.Open","params":{"item":{"playlistid":0,"position":0}}}]


RE: Working JSON RPC API Examples - IT007 - 2019-11-15

Hello, after hours of testing and experimenting I just have to accept that these API commands are too complicated for me. I hope someone can help.

I use Windows and Kodi 17.6 (dsplayer).

I want to stop playback with cmd (or powershell script etc.) before I close kodi.
I got this far, this url will work: http://user:pass@localhost:9696/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Stop","params":{"playerid":1}}

But I have no idea how to send this command with cmd or powershell without opening a browser.  I have downloaded curl but I can't figure out the syntax, it always errors out one way or the other. I would appreciate the help. As a bonus, api command to exit kodi would also be useful, taskkill /f is not very graceful.



Edit: Could not let it go and finally found an answer. Curl in windows needs extra backslashes. In case someone else happens to be searching how to stop kodi playback with windows cmd the following works for me:

curl -X POST -H "content-type:application/json" http://user:pass@localhost:9696/jsonrpc -d {\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"Player.Stop\",\"params\":{\"playerid\":1}}


RE: Working JSON RPC API Examples - MKANET - 2019-11-16

(2019-11-15, 17:02)IT007 Wrote: Hello, after hours of testing and experimenting I just have to accept that these API commands are too complicated for me. I hope someone can help.

I use Windows and Kodi 17.6 (dsplayer).

I want to stop playback with cmd (or powershell script etc.) before I close kodi.
I got this far, this url will work: http://user:pass@localhost:9696/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Stop","params":{"playerid":1}}

But I have no idea how to send this command with cmd or powershell without opening a browser.  I have downloaded curl but I can't figure out the syntax, it always errors out one way or the other. I would appreciate the help. As a bonus, api command to exit kodi would also be useful, taskkill /f is not very graceful.



Edit: Could not let it go and finally found an answer. Curl in windows needs extra backslashes. In case someone else happens to be searching how to stop kodi playback with windows cmd the following works for me:

curl -X POST -H "content-type:application/json" http://user:pass@localhost:9696/jsonrpc -d {\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"Player.Stop\",\"params\":{\"playerid\":1}}

Below are two WORKING commands that I use on Windows.  Just change the port and/or add a username/password for your setup.  I put these commands in STOP.cmd and PLAYPAUSE.cmd, respectively.  I actually execute these commands by telling Cortana... "Hey Cortana, pause Kodi" or "Hey Cortana resume Kodi"  or "Hey Cortana stop Kodi"  (using IFTTT.com and EventGhost for custom Cortana commands).


STOP example:

html:
curl -i -X POST -d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.Stop\", \"params\": { \"playerid\": 1 }, \"id\": 0}" -H "content-type:application/json" http://localhost:9696/jsonrpc


PLAY/PAUSE example:

html:
curl -i -X POST -d "{\"jsonrpc\": \"2.0\", \"method\": \"Player.Stop\", \"params\": { \"playerid\": 1 }, \"id\": 0}" -H "content-type:application/json" http://localhost:9696/jsonrpc



RE: Working JSON RPC API Examples - IT007 - 2019-11-16

Thanks, looks a bit cleaner that what I came up with. I use logitech harmony and needed this for the power off command to stop kodi playback before exiting.