How to send video title using JSON RPC API Player.Open
#1
I want to open a remote video using Player.Open. How do I send the video title? I have seen this posted in the forums a few times without a resolution. Is it even possible?

The following won't work:
json:

{
    "jsonrpc":"2.0",
    "id":"1",
    "method":"Player.Open",
    "params": {
        "item": {
            "file": "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/720/Big_Buck_Bunny_720_10s_30MB.mp4",
            "title": "Big Buck Bunny"        
        }
    }
}
Reply
#2
Sorry for the thread necro, just got here from a web search.

The solution to your problem is to add one level of indirection, using a custom Python video plugin and the "plugin://" protocol that Kodi understands:
json:
{
    "jsonrpc":"2.0",
    "id":"1",
    "method":"Player.Open",
    "params": {
        "item": {
            "file": "plugin%3A%2F%2Fplugin.video.mycustomplugin%2F%3Furl%3Dhttps%253A%252F%252Ftest-videos.co.uk%252Fvids%252Fbigbuckbunny%252Fmp4%252Fh264%252F720%252FBig_Buck_Bunny_720_10s_30MB.mp4%26title%3DBig%2BBuck%2BBunny"
        }
    }
}

That is, don't supply the raw media file, but rather your own plugin URL with any parameters either in the path (separated by slashes), OR appended at the end in URL-parameter form (that is, quote_plus encoded, like "plugin://plugin.video.mycustomplugin/?param1=value1&param2=value2&title=Big+Buck+Bunny").

Your plugin will be invoked and in its entry-point Python script you can read the URL parameters and do what you want, as long as you finish with a call to xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, myListItem) to resolve this indirection and start playback. That myListItem argument is a xbmcgui.ListItem with the raw media URL as the path and all the metadata you want, such as title, year etc.

If you want Kodi to use custom HTTP headers when requesting the media file, you can use the pipe symbol format in the raw media URL (with the names of headers as plaintext and their respective values quote_plus encoded): https://kodi.wiki/view/HTTP
Reply
#3
Thanks a lot "doko-desuka". It's been a while (and I can't test it right now), but if I ever get the need to do this again I'll give it a try and report back here.
Reply
#4
I've tried this with an extremely trivial plugin:

import sys
from urllib.parse import urlencode, parse_qsl
import xbmc
import xbmcgui
import xbmcplugin

# Get a plugin handle as an integer number.
HANDLE = int(sys.argv[1])

if __name__ == '__main__':
    paramstring = sys.argv[2][1:]
    params = dict(parse_qsl(paramstring))
    path = params['url']
    xbmc.log("Playing: {}".format(path),2)
    play_item = xbmcgui.ListItem(offscreen=True)
    play_item.setPath(path)
    xbmcplugin.setResolvedUrl(HANDLE, True, listitem=play_item)
    
But even though the correct url is displayed in the kodi log, nothing plays...

2024-03-04 15:07:36.739 T:3569608 warning <general>: Playing: https://ia600702.us.archive.org/3/items/..._512kb.mp4
Reply
#5
(2024-03-04, 16:09)sciurius Wrote: I've tried this with an extremely trivial plugin:

is this in response to this 2 year old post?
if yes, they're wanting a json-rpc solution to do this remotely not a minimal addon

or are you asking for help with your mini-addon?
Reply
#6
try:
python:
...
play_item = xbmcgui.ListItem(offscreen=True)
play_item.setProperty('IsPlayable','true')
...

scott s.
.
Reply
#7
I don't think it's going to work as it is, because when you enter your video plugin, Kodi expects it to make a folder (AKA directory) listing. So that call to xbmcplugin.setResolvedUrl() isn't gonna do anything, because that is only useful when a IsPlayable:true item has been selected, and its path points to a plugin path, rather than direct media path. So Kodi will call that plugin and expect it to "resolve" that path into a direct media path that it can play.

In other words, most of the time it's useful to defer resolving the final media path only when an item is actually played, rather than when it's only listed in the directory. So Kodi lets you set the item as playable, and when the user selects it, Kodi will navigate to its path (which might be something like "plugin://plugin.video.mycustomplugin/?id=55&otherParam=666"), and in that cycle you can do web requests, read directory files, whatever, and Kodi expects you to eventually call xbmcplugin.setResolvedUrl() with an actual media path that it can play. You "resolved" that plugin item into direct media.

There's two possible solutions here:
  1. Create the listing first with one or more IsPlayable:true list items with their paths set to those direct media files. When the user selects an item, Kodi will try to play its path.

  2. If you don't want to create a listing, and you want Kodi to play something as soon as you enter your video plugin, then you need to issue a "PLAY THIS THING" command, like xbmc.Player().play(play_item).
Reply
#8
Thanks for the reply. I already suspected that there was no selected item so there was nothing to play.
Your second suggestion does what I want.
Reply
#9
(2024-03-04, 23:45)scott967 Wrote: play_item = xbmcgui.ListItem(offscreen=True)
This is the first time I'm hearing about offscreen=True, very interesting. This thread here talks about it: https://forum.kodi.tv/showthread.php?tid=307394
Reply

Logout Mark Read Team Forum Stats Members Help
How to send video title using JSON RPC API Player.Open0