(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
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.