Script and json
#1
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:
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)
Reply
#2
I found some code! This is probably super messy! But I wanted to share it just in case someone else wanted to use it.

Script I use to send the JSON-RPC request
Code:
import requests
import json
import urllib
import sys
import time
import logging

logging.basicConfig(filename='example.log',format='%(asctime)s %(message)s',level=logging.DEBUG)
headers = {'content-type': 'application/json'}
xbmc_host = '192.168.2.149'
xbmc_port = 8082
xbmc_json_rpc_url = "http://" + xbmc_host + ":" + str(xbmc_port) + "/jsonrpc"
count = len(sys.argv) - 1

if count > 0:
    folder = sys.argv[1]
    logging.info('Folder is %s', folder)
    payload = {"jsonrpc": "2.0", "id": 0, "method": "Addons.ExecuteAddon", "params": {"addonid": "script.picture.nfcslideshow", "params": { "line1": ""+folder+"" } } }
    response = requests.post(xbmc_json_rpc_url, data=json.dumps(payload),
                             headers=headers)
    logging.info('Request sent')
else:
    logging.warning('No argument specified')

my script in addons\script.picture.nfcslideshow\default.py
Code:
import xbmcgui
import sys
import urlparse

class SlideShow:
    def __init__(self, line1):
        boop = line1[0]
        photodir = "D:\meep\\" +boop+ "\\"
        xbmc.executebuiltin("ActivateWindow(Pictures,"+photodir+")")
        xbmc.executebuiltin("Action(Play)")


count = len(sys.argv) - 1

if count > 0:
    params = urlparse.parse_qs('&'.join(sys.argv[1:]))
    window = SlideShow(**params)
    del window
Reply
#3
Not that I want to spoil your achievement, but it looks like the "Player.Open" method should start a slideshow if it's passed a directory as a parameter.
http://kodi.wiki/view/JSON-RPC_API/v6#Player.Open

If that's the case, then you should be able to do what you want with a single JSON call.

There's an example on this thread: http://forum.xbmc.org/showthread.php?tid=157996
Code:
//Slideshow of Images from a Directory "Images"
http://192.168.15.117/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"directory":"Images/"}}}
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#4
I appreciate your efforts but I have already looked into that solution. The issue there is that only images play in the slideshow and it skips all videos in the folder. I need videos and photos to play at the same time base on when a certain NFC tag is read.
Reply
#5
Ah - understood. The question of mixed content has come up before but I'm not sure I ever saw a resolution to it.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply

Logout Mark Read Team Forum Stats Members Help
Script and json0