JSON-RPC (JSON Remote Procedure Call) interface protocol in development for XBMC

  Thread Rating:
  • 7 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Montellese Offline
Team-XBMC Developer
Posts: 2,789
Joined: Jan 2009
Reputation: 20
Location: Switzerland
Post: #1981
(2012-05-25 10:55)mikebzh44 Wrote:  I start the slideshow with :

Code:
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Player.Open", "params": {"item": {"playlistid": 2, "position":0}}, "id": 1}' )

The slideshow start with the right picture but other pictures seem to be played in random mode.

Is there a way to play playlist in item order ? Those parameters cannot be used with playlistid ?

Code:
{
          "additionalProperties": false,
          "type": "object",
          "properties": {
            "path": {
              "required": true,
              "type": "string"
            },
            "random": {
              "default": true,
              "type": "boolean"
            },
            "recursive": {
              "default": true,
              "type": "boolean"
            }
          }

These can only be used if all your pictures are in the same directory. IIRC slideshows by default start in random mode so you will need to also pass the "shuffled": false property in the "options" parameter, i.e.:
Code:
{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "playlistid": 2, "position": 0 }, "options": { "shuffled": false } }, "id": 1 }

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
find quote
mikebzh44 Offline
Posting Freak
Posts: 1,060
Joined: Nov 2011
Reputation: 18
Location: Nantes - France
Post: #1982
OK. Thanks for the tip but pictures can be stored in differents directories.

My playlist :
C:\Pictures\Children\Photo1.jpg
C:\Pictures\Holidays\Photo1.jpg
C:\Pictures\Sports\Photo1.jpg

So shuffled is useless ?

"options" parameters is not referenced in documentation ??

Code:
{
  "returns": {
    "type": "string"
  },
  "params": [
    {
      "type": [
        {
          "additionalProperties": false,
          "type": "object",
          "properties": {
            "position": {
              "default": 0,
              "$ref": "Playlist.Position"
            },
            "playlistid": {
              "required": true,
              "$ref": "Playlist.Id"
            }
          }
        },
        {
          "$ref": "Playlist.Item"
        },
        {
          "additionalProperties": false,
          "type": "object",
          "properties": {
            "path": {
              "required": true,
              "type": "string"
            },
            "random": {
              "default": true,
              "type": "boolean"
            },
            "recursive": {
              "default": true,
              "type": "boolean"
            }
          }
        }
      ],
      "name": "item"
    }
  ],
  "description": "Start playback of either the playlist with the given ID, a slideshow with the pictures from the given directory or a single file or an item from the database."
}

http://wiki.xbmc.org/index.php?title=JSO...layer.Open

Sorry for my english, but, you know, I'm French so ...

find quote
Montellese Offline
Team-XBMC Developer
Posts: 2,789
Joined: Jan 2009
Reputation: 20
Location: Switzerland
Post: #1983
Ah the "options" parameter is only available in nightly builds (JSON-RPC API v5) and not in Eden (JSON-RPC API v4). If you are targeting Eden then you will need to start the slideshow with Player.Open and afterwards execute Player.UnShuffle.

But I have to say that the slideshow support is rather poor because XBMC's whole slideshow implementation/support is very basic and poor. So JSON-RPC methods in the Player and Playlist namespace may behave differently for slideshows than they do for music and video playback/items.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
find quote
mikebzh44 Offline
Posting Freak
Posts: 1,060
Joined: Nov 2011
Reputation: 18
Location: Nantes - France
Post: #1984
OK. As my target is Eden Stable, I will keep JSON V4.

SlideShow is basic but I only need to display 10 pictures from a Home widget so everything is OK for me.

Thanks a lot for your answers.

Have a nice and sunny week-end Wink

Sorry for my english, but, you know, I'm French so ...

find quote
Mizaki Offline
Fan
Posts: 662
Joined: Apr 2011
Reputation: 12
Post: #1985
There seems to be a problem with adding directories that are not in the library:
Code:
{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"item": {"directory": "/mnt/media/audio/Art Brut/Bang Bang Rock 'n Roll/"}, "playlistid": 0}, "id": 1}
Works and is in library.
Code:
{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"item": {"directory": "/mnt/media/music/A/How Ace Are Buildings/"}, "playlistid": 0}, "id": 1}
Does not work and is not in library. Invalid params is the error.

Am I missing something?

[Image: watched-clearlogo.jpg]
AWXi - Ajax web interface. Wiki
(This post was last modified: 2012-05-27 17:57 by Mizaki.)
find quote
mikebzh44 Offline
Posting Freak
Posts: 1,060
Joined: Nov 2011
Reputation: 18
Location: Nantes - France
Post: #1986
(2012-05-25 10:02)Montellese Wrote:  Yes using Playlist.Add is the right way but there are three errors in your request. First of all the first request is wrong, as there's no "type" property in the "item" parameter. The second request you posted looks better but the "playlistid" for picture playlists must be 2 and not 1 (1 is for video), you need to escape the backslashes in your path and the first "id" property in the "item" parameter does not belong there either. So it should look like this:
Code:
xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Playlist.Add", "params": { "playlistid": 2, "item": { "file": "C:\\Photos\\Leane_20111207_195415.jpg" } }, "id": 1 }')
There is somethind that I don't understand with \ and \\

Pictures path that have to be displayed in slideshow are stored in CommonCache.

Code:
cache.table_name = "MyPicsDB"
        _count = int(cache.get("MyPicsDB%s.Nb" %( _method )))
        for _i in range( 1,_count+1 ):
            _path = cache.get("MyPicsDB%s.%d.Path" %( _method, _i ))
            print("MyPicsDB%s.%d.Path=" %( _method, _i ), _path)
            _query = '{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "%s"}}, "id": 1}' %(_path)
            print("QUERY=",_query)
            _json_query = xbmc.executeJSONRPC(_query)
            _json_query = unicode(_json_query, 'utf-8', errors='ignore')
            _json_pl_response = simplejson.loads(_json_query)

So _path is OK and get \\ as _query but get a parse error from JSON :

Code:
10:32:57 T:2524  NOTICE: ('MyPicsDBLatest.1.Path=', u'C:\\Photos\\Leane_20111207_195415.jpg')
10:32:57 T:2524  NOTICE: ('QUERY=', u'{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "C:\\Photos\\Leane_20111207_195415.jpg"}}, "id": 1}')
10:32:57 T:2524   ERROR: JSONRPC: Failed to parse '{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "C:\Photos\Leane_20111207_195415.jpg"}}, "id": 1}'
10:32:57 T:2524  NOTICE: ('MyPicsDBLatest.2.Path=', u'C:\\Photos\\Leane_20110901_200610.jpg')
10:32:57 T:2524  NOTICE: ('QUERY=', u'{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "C:\\Photos\\Leane_20110901_200610.jpg"}}, "id": 1}')
10:32:57 T:2524   ERROR: JSONRPC: Failed to parse '{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "C:\Photos\Leane_20110901_200610.jpg"}}, "id": 1}'
10:32:57 T:2524  NOTICE: ('MyPicsDBLatest.3.Path=', u'C:\\Photos\\Leane_20110729_111400.jpg')
10:32:57 T:2524  NOTICE: ('QUERY=', u'{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "C:\\Photos\\Leane_20110729_111400.jpg"}}, "id": 1}')
10:32:57 T:2524   ERROR: JSONRPC: Failed to parse '{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "C:\Photos\Leane_20110729_111400.jpg"}}, "id": 1}'

I have try with :

Code:
_query = '{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "%s"}}, "id": 1}' %(normpath(_path))

But same issue Sad

The only way to get slideshow to work is :

Code:
_query = '{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "%s"}}, "id": 1}' %(_path.replace("\\","\\\\"))

It work on Windows but not on Linux :

Code:
19:57:57 T:2864687936   DEBUG: JSONRPC: Incoming request: {"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "/media/Disq500GO/Mes Photos/mont saint michel 2011/IMG_3469.JPG"}}, "id": 1}
19:57:57 T:2864687936   DEBUG: JSONRPC: Calling playlist.add
19:57:57 T:2864687936    INFO: -->Python script returned the following error<--
19:57:57 T:2864687936   ERROR: Error Type: <type 'exceptions.UnicodeEncodeError'>
19:57:57 T:2864687936   ERROR: Error Contents: 'ascii' codec can't encode character u'\xfb' in position 132: ordinal not in range(128)

How can I send the good path to JSON ?

Thanks.

Sorry for my english, but, you know, I'm French so ...

(This post was last modified: 2012-05-29 10:42 by mikebzh44.)
find quote
Montellese Offline
Team-XBMC Developer
Posts: 2,789
Joined: Jan 2009
Reputation: 20
Location: Switzerland
Post: #1987
I have no clue about python so I can't really help you there. All I can tell you is that in JSON (and in many (other) programming languages) the backslash \ is used as an escape character so you need to escape it with another backslash. If python uses the backslash as an escape character as well you'll need to escape it again (which is probably why you need the _path.replace("\\", "\\\\")).

Forward slashes / (which are used by linux for paths) don't need to be escaped.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
find quote
mikebzh44 Offline
Posting Freak
Posts: 1,060
Joined: Nov 2011
Reputation: 18
Location: Nantes - France
Post: #1988
OK.

Thanks.

Sorry for my english, but, you know, I'm French so ...

find quote
mikebzh44 Offline
Posting Freak
Posts: 1,060
Joined: Nov 2011
Reputation: 18
Location: Nantes - France
Post: #1989
OK for \ and \\ but I got an other issue with accent Sad

File on my PC :

C:\Photos\Août 2010.jpg

This path is stored on CommonCache and when I request CommonCache, I get UTF-8 String I suppose :

Code:
u'C:\\Photos\\Ao\xfbt 2010.jpg'

But if I want to add this path to Playlist with this code :

Code:
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "%s"}}, "id": 1}' %(_path))

I get an error :

Code:
Error Contents: 'ascii' codec can't encode character u'\xfb' in position 106: ordinal not in range(128)

I gess that JSON don't want UTF-8 string as if I call JSON this way :

Code:
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Playlist.Add", "params": {"playlistid": 2, "item": {"file" : "C:\\\\Photos\\\\Août 2010.jpg"}}, "id": 1}')

File is added to Playlist and played.

I've tried many things to encode/decode path from UTF-8 to ASCII or LATIN1 but now I'm lost and I don't know what to do Sad

Sorry for my english, but, you know, I'm French so ...

find quote
Montellese Offline
Team-XBMC Developer
Posts: 2,789
Joined: Jan 2009
Reputation: 20
Location: Switzerland
Post: #1990
This is again a python issue. In python unicode strings (as the one you retrieve from CommonCache seems to be) and standard strings are not interchangeable so you have to do the conversion between them manually. xbmc.executeJSONRPC() expects an UTF-8 encoded string and not a "python unicode string" so python complains when you try to put a unicode string into a standard string (even if its UTF-8 encoded).

Maybe you should ask in the addon/script development forum as there are many python addons/scripts that use JSON-RPC, maybe someone can help you there.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.

[Image: badge.gif]
find quote
Post Reply