Kodi Community Forum
Win need help with simple json-rpc script - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Win need help with simple json-rpc script (/showthread.php?tid=131289)

Pages: 1 2


need help with simple json-rpc script - KRA77 - 2012-05-11

I've been looking into json-rpc because I need to make a script that will a) update videolibrary b) update videolibrary with a specified file

I know that I can telnet 9090 and write

{ "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": 1 }

and it will update library, so I would think something like

echo { "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": 1 } > localhost:9090

from a .bat file would do the same, but it doesn't seem to work.

Any idea what is needed for this to work ?

Also if someone could help me with the code needed for it to parse only one spesified file, you know, I want a script that tells xbmc "hey, I added abc.avi to \\medialibrary\avi-files, please add it to your database"

And I want to do this from a windows .bat file or other script file that runs on windows. I would be thankfull for any help, but pls remember, I am no programmer Smile


RE: need help with simple json-rpc script - HenryFord - 2012-05-11

Here is a Powershell-Script that can script telnet with a certain set of commands you input:
http://powershell.com/cs/media/p/13938.aspx


RE: need help with simple json-rpc script - KRA77 - 2012-05-11

Thank you for your input, will look into this, I was hoping for a simple .bat solution but if this is what it takes.
For future reference http://technet.microsoft.com/en-us/library/ee176949.aspx

Any idea about the command for adding a single file to library.

I assume I need this one http://wiki.xbmc.org/index.php?title=JSON-RPC_API/v4#VideoLibrary.OnUpdate but how ?


RE: need help with simple json-rpc script - Bstrdsmkr - 2012-05-11

Try:

echo { "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": 1 } > telnet localhost:9090

Away from my machine right now, but I think that's what you're missing


RE: need help with simple json-rpc script - KRA77 - 2012-05-12

does not seem to work, afaik you don't need to use telnet, you just need to send the raw data to port 9090. I assume echo don't support outputting to tcp port.


RE: need help with simple json-rpc script - Bstrdsmkr - 2012-05-12

Well that was my bright idea lol

What about a python script?


RE: need help with simple json-rpc script - KRA77 - 2012-05-12

Thanks for trying anyway, I'm just trying to find the most noob friendly solution. I have a solution for linux that uses http:

wget -q -O/dev/null --header='Content-Type: application/json' --post-data='{"jsonrpc": "2.0", "method": "VideoLibrary.Scan"}' http://xbmc:[email protected]:8050/jsonrpc

This is also an option, but to do it on windows I would need something similar to wget.


RE: need help with simple json-rpc script - HenryFord - 2012-05-12

You could just use wget then... Wink
http://gnuwin32.sourceforge.net/packages/wget.htm


RE: need help with simple json-rpc script - KRA77 - 2012-05-12

Yeah, but unfortunatly it's not as easy as to download wget for windows, the same command doesn't work Sad


RE: need help with simple json-rpc script - Bstrdsmkr - 2012-05-12

Same command as in still sending to /dev/null? Try %temp% instead


RE: need help with simple json-rpc script - KRA77 - 2012-05-12

First thing I tried was simply removing the output option, but that didn't work, then I tried with %temp% and the result:

C:/Users/Kay/AppData/Local/Temp: Permission denied

Sad

Even running cmd in administrator mode gives same permission denied



RE: need help with simple json-rpc script - KRA77 - 2012-05-12

Finally got it to run with

wget -q -Oc:\users\kay\jsonrpc.log --header='Content-Type: application/json' --post-data='{"jsonrpc": "2.0", "method": "VideoLibrary.Scan"}' http://xbmc:[email protected]:8050/jsonrpc

Unfortunatly it returns:

{"error":{"code":-32700,"message":"Parse error."},"id":null,"jsonrpc":"2.0"}

Tried adding a ID

wget -q -Oc:\users\kay\jsonrpc.log --header='Content-Type: application/json' --post-data='{"jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": 1 }' http://xbmc:[email protected]:8050/jsonrpc

Still same error...


RE: need help with simple json-rpc script - HenryFord - 2012-05-13

(2012-05-12, 19:30)KRA77 Wrote: C:/Users/Kay/AppData/Local/Temp: Permission denied
And that is a good thing. You cannot redirect the output to a folder, you have to specify a file.

However - this should fix your problem:
Code:
wget -q -Oc:\users\kay\jsonrpc.log --header='Content-Type: application/json' --post-data="{\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.Scan\", \"id\":1}" http://xbmc:[email protected]:8050/jsonrpc




RE: need help with simple json-rpc script - KRA77 - 2012-05-13

success !!

Thanks for sticking with it, I kindo figured the spaces was making problems, didn't know how to solve it, thank you.

Now the tricky part doing a single file update, and not full library update.

I'm thinking of doing this with a batfile with filename arguments, so just hardcode the path in bat file, and use

%~nx1

as code inside that bat file do add filename to the code.

I though I could use VideoLibrary.OnUpdate for that, but looking into it, I'm not so sure anymore.


RE: need help with simple json-rpc script - Mizaki - 2012-05-13

I believe you can only update a specific path if you are using Frodo.