Files.PrepareDownload
#1
Hello,
Since I moved to windows, I have been struggling with the "Parse error."
If anybody can have a look at my code It would be great.

The first Call gives me back the "file" attribute
Code:
{ "jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": { "movieid": 3, "properties": [ "genre", "director", "cast", "tagline", "plot", "title", "lastplayed", "runtime", "year", "playcount", "rating", "thumbnail", "file" , "art" , "plotoutline" , "trailer"  ] }, "id": 1 }

Then I use the file attribute to call the Files.PrepareDownload
Code:
{"jsonrpc": "2.0", "params": {"path": "D:\Movies\Confessions of a Shopaholic (2009)\Confessions of a Shopaholic (2009).mp4" }, "method": "Files.PrepareDownload", "id": "1" }

But here is my return code :
Code:
{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}


Any Idea ?
I use a POST ajax query (JQuery) to get the list of my movies and get the link to download.
Reply
#2
It's probably the backslashes in the path, use slashes or escape them.

jonib
XBMC2, EventGhost plugin. Image
Reply
#3
Forward slashes will probably work however the problem is that special characters need to be escaped using backslash in json. \ is one of these characters. Replacing \ with \\ in your file name should work. See http://www.json.org/ (diagram string)

If you look at the response string sent by Kodi you can see that the file name contains \\ and not \. JQuery probably decodes the string and you are using it for Files.PrepareDownload without reencoding it.

Edit: just realized that jonib already wrote about escaping backslash...
Reply
#4
Here is the reply from KODI
Code:
....
cast: [{name: "Isla Fisher", order: 0, role: "Rebecca Bloomwood",…},…]
file: "D:\\Movies\\Confessions of a Shopaholic (2009)\\Confessions of a Shopaholic (2009).mp4"
thumbnail:"image://http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2f8gCZJ8gOxd22Spz1MKiu4b54T2r.jpg/"
...

You are right Jquery decodes but doesnt recode so I I tried manually adding backslaches

D:\\Movies\\Confessions of a Shopaholic (2009)\\Confessions of a Shopaholic (2009).mp4\\
Still get a "Parse error." !

I tried replacing backslaches with slashes
D:/Movies/Confessions of a Shopaholic (2009)/Confessions of a Shopaholic (2009).mp4/
I am getting invalid params

Code:
error:{code: -32602, data: {details: null}, message: "Invalid params."}

I tried encoding the reply from KODI using encodeURI() function.
Code:
D:%5CMovies%5CConfessions%20of%20a%20Shopaholic%20(2009)%5CConfessions%20of%20a%20Shopaholic%20(2009).mp4
and even added manually a final backslash
Code:
D:%5CMovies%5CConfessions%20of%20a%20Shopaholic%20(2009)%5CConfessions%20of%20a%20Shopaholic%20(2009).mp4%5C
Tried it with the slashes instead of backslashes
Doesnt work! getting invalid params

Help !
Reply
#5
Maybe try using your webbrowser to rule out potential problems in your code.

You can retrieve movie details using a GET request
Code:
http://localhost:8080/jsonrpc?request={"jsonrpc":"2.0","method":"VideoLibrary.GetMovieDetails","params":{"movieid":1,"properties":["file"]},"id":1}

I get the following response with double backslashes back from Kodi (version 16.1)
Code:
{"id":1,"jsonrpc":"2.0","result":{"moviedetails":{"file":"C:\\Movies\\Inception.avi","label":"Inception","movieid":1}}}

And then Files.PrepareDownload
Code:
http://localhost:8080/jsonrpc?request={"jsonrpc":"2.0","params":{"path":"C:\\Movies\\Inception.avi"},"method":"Files.PrepareDownload","id":"1"}

returns
Code:
{"id":"1","jsonrpc":"2.0","result":{"details":{"path":"vfs/C%3a%5cMovies%5cInception.avi"},"mode":"redirect","protocol":"http"}}
Reply
#6
(2016-09-07, 10:23)Slimo Wrote: D:\\Movies\\Confessions of a Shopaholic (2009)\\Confessions of a Shopaholic (2009).mp4\\
D:/Movies/Confessions of a Shopaholic (2009)/Confessions of a Shopaholic (2009).mp4/
There should not be (back)slashes after .mp4

jonib
XBMC2, EventGhost plugin. Image
Reply
#7
Thank you for your answers. I could get the right download link when I maually add the double backslashes.
But with javascript it seems that ajax is removing the double backslashes..
I have been really struggling and cant seem to find a way to get the ajax raw data.
any ideas would be great.

When I access the response data.moviedetails.file , javascript removes the double backslashes.

For people using windows and jquer/ajax here is the temporary fix I found ... but ... if you have a suggestion feel free

Code:
var NewMovieUrltmp    = JSON.stringify(data.result.moviedetails.file);
var NewMovieUrltmp2  = NewMovieUrltmp.substring(1, NewMovieUrltmp.length-1);
var NewMovieUrl         = encodeURI(NewMovieUrltmp2);
Reply
#8
(2016-09-09, 00:02)Slimo Wrote: I have been really struggling and cant seem to find a way to get the ajax raw data.
any ideas would be great.
Try escaping the backslashes twice as in if there are one backlash in the path put four backslashes.

jonib
XBMC2, EventGhost plugin. Image
Reply
#9
I am trying not to edit the ajax response in order to make it work on other systems(on linux the data.result.moviedetails.file response works without editing)
But it seems like the only option..
Reply

Logout Mark Read Team Forum Stats Members Help
Files.PrepareDownload0