JSON RPC API - Remote Video Playback
#1
Hi all,

I have a raspberry PI 4 set up with LibreElec and my goal is to play a file using the remote API. Remote control from other machines is enabled. I'm having no luck playing a file using the following method (using POST):

json:
http://192.168.0.23:8080/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"file":"[email protected]"}}}

Response is:

json:
{
"error": {
"code": -32700,
"message": "Parse error."
},
"id": null,
"jsonrpc": "2.0"
}

This GET request works:

json:
​​​​​​​http://192.168.0.23:8080/jsonrpc?request={"jsonrpc": "2.0", "id": 1, "method": "Playlist.GetPlaylists"}

With the response:

json:
{
"id": 1,
"jsonrpc": "2.0",
"result": [
  {
"playlistid": 0,
"type": "audio"
},
  {
"playlistid": 1,
"type": "video"
},
  {
"playlistid": 2,
"type": "picture"
}
],
}

I've come across various posts and examples asking this question but I can't seem to find a working solution. Any tips would be very much appreciated.

Cheers!
Reply
#2
Hello? Echo...
Reply
#3
I'm using JSONRPC in to start playback on Kodi but not exactly the way you are. I'm using library id so mine is.

javascript:
{"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"movieid":1234},"options":{"resume":true}}}

The only thing I can recommend to you is that I don't see a path in your RPC call so try it with a full path, library path or plugin path (that is videodb:// plugin:// smb:// or /local/ or C:\ etc)
Reply
#4
Your post should be done to http://192.168.0.23:8080/jsonrpc with the following post payload: {"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"file":"[email protected]"}}}
I.e., the data you post should not be passed as a query argument in the url.
Reply
#5
Thank you for your reply! I'm a bit new to this, can you please tell me what the correct format would be?
Reply
#6
Any thoughts? I'm not sure how to resolve this
Reply
#7
i think what youre lacking is that the rpc needs to be sent as a POST request with data instead of a GET request with url parameters
i wrote up a quickie to help you, i dont do this for everyone

python:
#without authentication

from urllib.request import Request, urlopen  # Python 3
req = Request(
    'http://192.168.0.0:8080/jsonrpc'
)
procedure='{"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"movieid":99999},"options":{"resume":true}}}'
response = urlopen(req, data=procedure.encode('utf-8')).read()

#with authentication

from urllib.request import Request, urlopen  # Python 3
import base64 # verify this is for Python 3
userpass = "kodi:kodi" #format username:password as set in kodi
req = Request(
    'http://192.168.0.0:8080/jsonrpc',
    headers={'Content-Type': 'application/json',"Authorization" : "Basic {}".format(base64.b64encode(userpass))}
)
procedure='{"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"movieid":99999},"options":{"resume":true}}}'
response = urlopen(req, data=procedure.encode('utf-8')).read()

just change the variable procedure to a quoted json payload for the command you wish to send, if you enable authentication in the kodi web interface you can use the second code set and it will perform the request with a Basic HTTP Authentication, double check the base64 stuff please it was just a quick write up and it could be incorrect for the current kodi version
Reply

Logout Mark Read Team Forum Stats Members Help
JSON RPC API - Remote Video Playback0