forked from SerpentDrago/plugin.program.autocompletion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.py
executable file
·91 lines (74 loc) · 2.91 KB
/
plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# -*- coding: utf8 -*-
# Copyright (C) 2015 - Philipp Temminghoff <[email protected]>
# This program is Free Software see LICENSE file for details
import sys
import xbmc
import xbmcgui
import xbmcplugin
import xbmcaddon
import json
import AutoCompletion
ADDON = xbmcaddon.Addon()
ADDON_VERSION = ADDON.getAddonInfo('version')
def get_kodi_json(method, params):
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "%s", "params": %s, "id": 1}' % (method, params))
return json.loads(json_query)
def start_info_actions(infos, params):
for info in infos:
if info == 'autocomplete':
listitems = AutoCompletion.get_autocomplete_items(params["id"], params.get("limit", 10))
elif info == 'selectautocomplete':
xbmc.executebuiltin('Dialog.Close(busydialog)')
xbmc.sleep(600)
get_kodi_json(method="Input.SendText", params='{"text":"%s", "done":false}' % params.get("id"))
return
pass_list_to_skin(data=listitems, handle=params.get("handle", ""), limit=params.get("limit", 20))
def pass_list_to_skin(data=[], handle=None, limit=False):
if data and limit and int(limit) < len(data):
data = data[:int(limit)]
if not handle:
return None
if data:
items = create_listitems(data)
xbmcplugin.addDirectoryItems(handle=handle,
items=[(i.getProperty("path"), i, False) for i in items],
totalItems=len(items))
xbmc.executebuiltin('Dialog.Close(busydialog)')
xbmcplugin.endOfDirectory(handle)
def create_listitems(data=None):
if not data:
return []
itemlist = []
for (count, result) in enumerate(data):
listitem = xbmcgui.ListItem(str(count))
for (key, value) in result.items():
if not value:
continue
if key.lower() in ["label"]:
listitem.setLabel(value)
elif key.lower() in ["search_string"]:
path = "plugin://plugin.program.autocompletion/?info=selectautocomplete&&id=%s" % value
listitem.setPath(path=path)
listitem.setProperty('path', path)
listitem.setProperty("index", str(count))
listitem.setProperty("isPlayable", "false")
itemlist.append(listitem)
return itemlist
if (__name__ == "__main__"):
xbmc.log("version %s started" % ADDON_VERSION)
args = sys.argv[2][1:]
handle = int(sys.argv[1])
infos = []
params = {"handle": handle}
delimiter = "&&"
for arg in args.split(delimiter):
param = arg.replace('"', '').replace("'", " ")
if param.startswith('info='):
infos.append(param[5:])
else:
try:
params[param.split("=")[0].lower()] = "=".join(param.split("=")[1:]).strip()
except Exception:
pass
if infos:
start_info_actions(infos, params)