2013-04-07, 12:37
One PR per change/feature/fix please.
(2013-04-11, 05:09)MilhouseVH Wrote: @Montellese: Can individual JSON socket responses be terminated by a "\n" (or even "\0"/null, whatever is most suitable).
While performing a video library rescan I tried to run some JSON queries (eg. GetMovies) and the response I got over sockets included not only the movie data, but also concatenated on the end of this response was a VideoLibrary.OnUpdate notification. Since this response now contained two messages, it was impossible to parse.
At least if each message in a response were terminated with a "\n" it might be possible to split the response into individual messages (sub-responses) and process them individually. Without any suitable termination this is nigh on impossible. Terminators would also simplify socket reading, as you could more easily tell when all the available data has been read, by checking for a terminator within the retrieved data.
(2013-04-11, 07:51)Montellese Wrote: This has been asked at least 5 times in the past and the answer hasn't changed: no.
(2013-04-11, 07:51)Montellese Wrote: A proper JSON stream parser should ignore anything in between a final closing } and an initial opening { so adding something in between simply doesn't make sense.
(2013-04-11, 07:51)Montellese Wrote: And it's far from impossible to count opening and closing { } to determine when a message is finished. If you use the search there are quite some example code snippets that show how it can be done.
(2013-04-11, 18:10)MilhouseVH Wrote: I'd have hoped there might be a way to make it optional.So that your application only works with xbmc installations that have the option enabled?
(2013-04-11, 18:10)MilhouseVH Wrote: So a "proper" JSON parser shouldn't have any problem with a message terminated by a newline then? Although that's not the problem I'm raising, it's the concatenation of two objects in a single response, which can't then be parsed as it throws an "extra data" exception (although maybe the standard json module in Python isn't "proper"?)The problem is that you consider the TCP socket to work in messages but it's just a stream of bytes/characters. There's no message structure or anything. You read one byte after another and read and read until there's no more data or until the next higher layer has detected a packet/message. In this case the next higher layer is the logic that counts { and } and only forwards that part of the received data that it detected as a whole JSON-RPC request (or JSON object). Obviously you can't pass two JSON objects to python's JSON parser.
(2013-04-11, 07:51)Montellese Wrote: And it's far from impossible to count opening and closing { } to determine when a message is finished. If you use the search there are quite some example code snippets that show how it can be done.
(2013-04-11, 18:10)MilhouseVH Wrote: Out of interest if you know of any examples you can point me to, that would help - I've searched on this subject previously and not found anything useful, beyond people saying it can be done "if you have to" as other methods (length prefix, message terminator) are acknowledged as preferred implementations.I'd have to use the same search functionalities as are available to you. All I need to know is that topfs2 and myself have discussed this topic quite a few times and there have been code examples (probably even in python) on how to do it.
{jsonrpc": "2.0", "method": "VideoLibrary.GetMovieSetDetails", "params": {"setid": %s, "properties": [ "thumbnail" ], "movies": { "properties": [ "rating", "art", "file", "year", "director", "writer","genre" , "thumbnail", "runtime", "studio", "plotoutline", "plot", "country"], "sort": { "order": "ascending", "method": "year" }} },"id": 1}
(2013-04-18, 21:12)Wanilton Wrote: With This request I receive one error in latest gotham master code:
Code:{jsonrpc": "2.0", "method": "VideoLibrary.GetMovieSetDetails", "params": {"setid": %s, "properties": [ "thumbnail" ], "movies": { "properties": [ "rating", "art", "file", "year", "director", "writer","genre" , "thumbnail", "runtime", "studio", "plotoutline", "plot", "country"], "sort": { "order": "ascending", "method": "year" }} },"id": 1}
I receive error
{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}
Any tip how I solve this.