Hi, when i try to get fanart url with Files.PrepareDownload, it responses error.
first I get movies with VideoLibrary.GetMovies:
Code:
http://<ip>/jsonrpc?request={"jsonrpc": "2.0", "params": {"sort": {"order": "ascending", "method": "title"}, "properties": ["title", "art", "file"]}, "method": "VideoLibrary.GetMovies", "id": "libMovies"}
VideoLibrary.GetMovies Response:
Code:
{"id":"libMovies","jsonrpc":"2.0","result":{"limits":{"end":1,"start":0,"total":1},"movies":[{"art":{"fanart":"image://http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2f3Kgu3ys6W6UZWWFty7rlTWgST63.jpg/","poster":"image://http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2fg23cs30dCMiG4ldaoVNP1ucjs6.jpg/"},"file":"D:\\Movie\\Film\\Fantastic.Four.2015.720p.BluRay.x264-GECKOS\\Fantastic.Four.2015.720p.BluRay.x264-GECKOS.mkv","label":"Fantastic Four","movieid":1,"title":"Fantastic Four"}]}}{"jsonrpc":"2.0","method":"GUI.OnScreensaverActivated","params":{"data":null,"sender":"xbmc"}}
Then i try to get prepared url with Files.PrepareDownload:
Request:
Code:
http://<ip>/jsonrpc?request={"jsonrpc": "2.0", "params": {"path": "image://http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2f3Kgu3ys6W6UZWWFty7rlTWgST63.jpg/"}, "method": "Files.PrepareDownload", "id": "preparedl"}
Files.PrepareDownload Response:
Code:
{"error":{"code":-32602,"data":{"details":null},"message":"Invalid params."},"id":1,"jsonrpc":"2.0"}
Can anyone help me?
You need to do a POST to Files.PrepareDownload
(2015-11-27, 21:50)Razze Wrote: [ -> ]You need to do a POST to Files.PrepareDownload
would you give me an example about how to do it?
100% of JSON queries works as GET or POST, the only limitations are this one and Files.Download can not work over Websocket / TCP, only HTTP.
(2015-11-29, 20:17)Razze Wrote: [ -> ] (2015-11-27, 23:01)hrrs Wrote: [ -> ] (2015-11-27, 21:50)Razze Wrote: [ -> ]You need to do a POST to Files.PrepareDownload
would you give me an example about how to do it?
Have a look at this code, it might help you to understand what I mean with POST instead of GET
https://github.com/MilhouseVH/texturecac...e.py#L2178
I read the code from the link you gave then i tried to do POST but it response Parse error, here is my code:
Code:
private static final String POST_URL = "http://<ip>/jsonrpc";
private static final String POST_PARAMS = "request={\"jsonrpc\": \"2.0\", \"params\": {\"path\": \"image://http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2fkvXLZqY0Ngl1XSw7EaMQO0C1CCj.jpg/\"}, \"method\": \"Files.PrepareDownload\", \"id\": \"preparedl\"}";
Code:
private static void sendPOST() throws IOException
{
URL obj = new URL(POST_URL);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setDoOutput(true);
OutputStream os = con.getOutputStream();
os.write(POST_PARAMS.getBytes());
os.flush();
os.close();
int responseCode = con.getResponseCode();
System.out.println("POST Response Code :: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK)
{
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null)
{
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
}
else
{
System.out.println("POST request not worked");
}
}
Response:
Code:
{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}
Could you please have a look at this? What am i missing here?
You do not have to use a POST for JSON-RPC, a GET works fine.
If JSON-RPC returns the url in the format image:// you can access the cached image in the following manner without using Files.PrepareDownload:
So:
VideoLibrary.GetMovies Response:
Code:
{"id":"libMovies","jsonrpc":"2.0","result":{"limits":{"end":1,"start":0,"total":1},"movies":[{"art":{"fanart":"image://http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2f3Kgu3ys6W6UZWWFty7rlTWgST63.jpg/","poster":"image://http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2fg23cs30dCMiG4ldaoVNP1ucjs6.jpg/"},"file":"D:\\Movie\\Film\\Fantastic.Four.2015.720p.BluRay.x264-GECKOS\\Fantastic.Four.2015.720p.BluRay.x264-GECKOS.mkv","label":"Fantastic Four","movieid":1,"title":"Fantastic Four"}]}}{"jsonrpc":"2.0","method":"GUI.OnScreensaverActivated","params":{"data":null,"sender":"xbmc"}}
to get the fanart replace 'image://' with 'http://localhost/image/' to get 'http://localhost/image/http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2f3Kgu3ys6W6UZWWFty7rlTWgST63.jpg'
(note you may to need use an actual ip address and port value in place of localhost, depending on your configuration)
so to access the cached fanart image use:
Code:
http://localhost/image/http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2f3Kgu3ys6W6UZWWFty7rlTWgST63.jpg
Note that this must be done via an http request.Please see:
http://kodi.wiki/view/Webserver#Image_cache_.2Fimage
You can quickly test the URL by using a browser - make sure that Kodi is enabled to allow control via HTTP.
No
Please do not do that
This does make Kodi download the image each time and return the original and not the cached one ! This is bad for TMDB at least and ugly performance !
If you want to do it manually you need to use :
http://localhost/image/ + urlencode(full image path returned by Kodi with image://)
For this example it would be :
http://localhost/image/image%3A%2F%2Fhtt...T63.jpg%2F
But Files.PrepareDownload does the job for you, to debug the problem of parsing as always Kodi logs are mandatory (with JSON logging activated)
(2015-12-01, 10:43)Tolriq Wrote: [ -> ]No
Please do not do that
This does make Kodi download the image each time and return the original and not the cached one ! This is bad for TMDB at least and ugly performance !
If you want to do it manually you need to use : http://localhost/image/ + urlencode(full image path returned by Kodi with image://)
For this example it would be : http://localhost/image/image%3A%2F%2Fhtt...T63.jpg%2F
But Files.PrepareDownload does the job for you, to debug the problem of parsing as always Kodi logs are mandatory (with JSON logging activated)
@
Tolriq, is absolutely correct in what he's saying about the request I gave bypassing the cache. I didn't notice it until I enabled the libcURL on the debug logs to see the request going out http. DO NOT DO THAT! sorry for the bum steer.
However, I can't get either the Files.PrepareDownload or the manual
http://localhost/image/ + urlencode(full image path returned by Kodi with image://) to work. There's not much in the debug log (even with all components enabled), just the incoming request.
Well it works for million users
Either you use wrong image url (do not forget the leading /) or your urlencode is not good.
http://meyerweb.com/eric/tools/dencoder/ This one works for perfectly for manual tests.
For PrepareDownload I do not use it as it's slower than doing it manually so not aware of potential bugs but it works here
Code:
{"jsonrpc": "2.0", "params": {"path": "image://music@smb%3a%2f%2fdiskstation%2fred%2fmusic%2f%5bDivers%5d%2f4%20Non%20Blondes%20-%20What%27s%20Up.mp3/"}, "method": "Files.PrepareDownload", "id": "preparedl"}
From copy pasting the first post code there's a strange character not visible just before the leading / so it have tons of chance to be the problem.
Ah I see, you have to urlencode the urlencoded url that comes back from the VideoLibrary.GetMovies call.
so this:
Code:
"image://http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2f6LnwpadKFRrqam7IfBAi3lNTz6Y.jpg/"
becomes this:
Code:
"image%3A%2F%2Fhttp%253a%252f%252fimage.tmdb.org%252ft%252fp%252foriginal%252f6LnwpadKFRrqam7IfBAi3lNTz6Y.jpg%2F"
then it works in the Files.PrepareDownload or
http://localhost/image/+(above url). I learn something every day.
Well for Files.PrepareDownload in GET mode you need to urlencode not for POST.
I think wiki explains that.
But this is more HTTP things than Kodi JSON.
So, going back to the original post and question about an http request for Files.PrepareDownload:
(2015-11-26, 23:12)hrrs Wrote: [ -> ]Then i try to get prepared url with Files.PrepareDownload:
Request:
Code:
http://<ip>/jsonrpc?request={"jsonrpc": "2.0", "params": {"path": "image://http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2f3Kgu3ys6W6UZWWFty7rlTWgST63.jpg/"}, "method": "Files.PrepareDownload", "id": "preparedl"}
Files.PrepareDownload Response:
Code:
{"error":{"code":-32602,"data":{"details":null},"message":"Invalid params."},"id":1,"jsonrpc":"2.0"}
Can anyone help me?
Changing
Code:
http://<ip>/jsonrpc?request={"jsonrpc": "2.0", "params": {"path": "image://http%3a%2f%2fimage.tmdb.org%2ft%2fp%2foriginal%2f3Kgu3ys6W6UZWWFty7rlTWgST63.jpg/"}, "method": "Files.PrepareDownload", "id": "preparedl"}
to
Code:
http://<ip>/jsonrpc?request={"jsonrpc": "2.0", "params": {"path": "image%3A%2F%2Fhttp%253a%252f%252fimage.tmdb.org%252ft%252fp%252foriginal%252f3Kgu3ys6W6UZWWFty7rlTWgST63.jpg%2F"}, "method": "Files.PrepareDownload", "id": "preparedl"}
should work.
Well to be complete the correct answer is written in Kodi Wiki
http://kodi.wiki/view/JSON-RPC_API#GET
The complete request part should be url encoded not just one parameter in it.
So fully correct answer would be :
Code:
http://<ip>/jsonrpc?request=%7B%22jsonrpc%22%3A%20%222.0%22%2C%20%22params%22%3A%20%7B%22path%22%3A%20%22image%3A%2F%2Fhttp%253a%252f%252fimage.tmdb.org%252ft%252fp%252foriginal%252f3Kgu3ys6W6UZWWFty7rlTWgST63.jpg%E2%80%8B%2F%22%7D%2C%20%22method%22%3A%20%22Files.PrepareDownload%22%2C%20%22id%22%3A%20%22preparedl%22%7D
@
hrrs, so now you have a complete solution inclusive of several examples of what not to do.