Adding file with accent to SlideShow with JSON
#1
Hello.

I'm try to add some pictures to playlist to play slideshow. Everthing is OK when picture hav no accent in it's name or path.

But if I want to add, C:\Photos\Août 2010.jpg, I get a JSON error.

You can find a detailed message of what I'm doing here :

http://forum.xbmc.org/showthread.php?tid...pid1114705

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

Main HTPC : Odroid-C2 running CoreELEC with Titan Bingie
Secondary HTPC : Freebox Mini 4K running Android TV with Titan Bingie
Reply
#2
So path get from CommonCache is a unicode variable :

Code:
_path = cache.get("MyPicsDB%s.%d" %( _method, i ))

LOG:
('_path =', u'C:\\Photos\\Ao\xfbt 2010.jpg')
('type =', <type 'unicode'>)

But JSON is waiting for UTF8 string :

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

LOG :
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfb' in position 105: ordinal not in range(128)

same issue with :


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

How can I cast unicode variable to UTF8 variable ?
Sorry for my english, but, you know, I'm French so ...

Main HTPC : Odroid-C2 running CoreELEC with Titan Bingie
Secondary HTPC : Freebox Mini 4K running Android TV with Titan Bingie
Reply
#3
Try:

Code:
path = "C:\Photos\Août 2010.jpg"
path = path.encode("utf-8")
Reply
#4
Thanks.

I've found by my self :

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

But maybe the str() is useless.
Sorry for my english, but, you know, I'm French so ...

Main HTPC : Odroid-C2 running CoreELEC with Titan Bingie
Secondary HTPC : Freebox Mini 4K running Android TV with Titan Bingie
Reply
#5
Yeah, I don't think the str() is helping there. Not going to hurt anything to have it there, but I think encode() can only return a str anyway
Reply

Logout Mark Read Team Forum Stats Members Help
Adding file with accent to SlideShow with JSON0