Example #1
0
 def print_list_of_dicts(l):
     r = 1
     for i in l:
         label = i.get('label', None)
         print '  %s) %s' % (r, ascii(label) or i)
         for k, v in i.items():
             try:
                 print '   %s:%s' % (k, v)
             except UnicodeError as e:
                 print '   *%s' % e
                 print '   %s:%s' % (ascii(k), ascii(v))
         r += 1
Example #2
0
    def send_json(self, path=None, params=None, method=None):
        method = method or "Files.GetDirectory"
        json_query = {
            "jsonrpc":"2.0",
            "method": method,
            "params":{
                "properties": ["thumbnail"],
            },
            "id": 1}
        json_query['params'].update(params or {})

        if method == "Files.GetDirectory":
            if not path:
                raise Exception('send_json requires a path when the method is "Files.GetDirectory".')
            directory = self.address+self._get_query_path(path)
            json_query['params']["directory"] = directory

        # exicute server call
        json_query = json.dumps(json_query, ensure_ascii=False).encode('utf8')
        print '1 SEARCH -> Plugin.send_json to (%s):%s' % (self.id, json_query)
        try:
            data = xbmc.executeJSONRPC(uni(json_query))
        except UnicodeEncodeError:
            data = xbmc.executeJSONRPC(ascii(json_query))
        data = uni(data)
        json_obj = json.loads(data)

        # handle errors and debug
        self.print_response(json_obj, path)
        error = json_obj.get('error', None)
        if error:
            print '1 SEARCH -> JSONPRC ERROR: %s' % json_obj

        return json_obj