2014-10-16, 01:29
Hey guys, I am really new to python and I don't understand the JSON at all. Currently I made a simple script that takes the variables passed to it and will run a slideshow based on that variable. But I have NO idea how to do this through the JSON API. I can launch the addon from json, but I dont know how to add some kind of interpreter to take an argument or even pass one to the addon from json. Any help would be greatly appreciated.
PLEASE NOTE, THIS IS A COMPILATION OF CODE I HAVE FOUND ON THE NET. I also checked out numerous tutorials on the wiki and even using the "picture/video addon tutorial" I was unable to get JSON calls to work. Help please!
(I'm using windows 7 with kodi 14.0 alpha release.)
script code:
python script used to send JSON commands.
PLEASE NOTE, THIS IS A COMPILATION OF CODE I HAVE FOUND ON THE NET. I also checked out numerous tutorials on the wiki and even using the "picture/video addon tutorial" I was unable to get JSON calls to work. Help please!
(I'm using windows 7 with kodi 14.0 alpha release.)
script code:
Code:
import xbmcgui
import xbmc
import sys
count = len(sys.argv) - 1
if count > 0:
photodir = "D:\xxxx\xxxx\xxxx\pics\\" +sys.argv[1]+ "\\"
xbmc.executebuiltin("ActivateWindow(Pictures,"+photodir+")")
xbmc.executebuiltin("Action(Play)")
else:
xbmcgui.Dialog().ok("Status","You cannot run this script directly. It must be called by an NFC tag.")
python script used to send JSON commands.
Code:
import requests
import json
import urllib
headers = {'content-type': 'application/json'}
xbmc_host = '192.168.xxx.xxx'
xbmc_port = 8082
xbmc_json_rpc_url = "http://" + xbmc_host + ":" + str(xbmc_port) + "/jsonrpc"
payload = {"jsonrpc": "2.0", "method": "Addons.ExecuteAddon", "params": { "addonid": "plugin.picture.nfcslideshow" }, "id": 1}
response = requests.post(xbmc_json_rpc_url, data=json.dumps(payload),
headers=headers)