-
Notifications
You must be signed in to change notification settings - Fork 12
/
addon.py
296 lines (233 loc) · 9.87 KB
/
addon.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
"""idolpx Installer"""
import xbmc, xbmcgui
import os, sys, json, time, shutil
from libs import requests
from libs import kodi
import installer
# Initialize Global Variables
window = xbmcgui.Window(10000)
current = json.loads('{"config_version": "00000000","test_version": "00000000"}')
current_version = '00000000'
remote = json.loads('{"config_version": "00000000","test_version": "00000000"}')
remote_version = '00000000'
version_file = ''
url = ''
hash = ''
def getParams():
params = {
'd' : kodi.get_mac(),
'os': kodi.get_info('System.OSVersionInfo'),
'id': kodi.get_setting('deviceid'),
'kv': kodi.get_version()
}
return params
# Get Current Version
def getLocalVersion():
global current, current_version, version_file
path = xbmc.translatePath('special://userdata')
version_file = path+'version.json'
kodi.debug(version_file)
try:
current = json.load(open(version_file))
# Prompt for Configuration Update
if kodi.get_setting('update_test') != 'true':
current_version = current['config_version']
else:
current_version = current['test_version']
except Exception, e:
kodi.debug('getLocalVersion: '+str(e))
kodi.debug('Current Version: '+current_version)
# Get Remote Settings
def getRemoteVersion():
global remote, remote_version, url, hash
dp = xbmcgui.DialogProgress()
dp.create('idolpx Installer',
'Checking for update...',
'',
'Please wait...')
dp.update(100)
try:
# Prompt for Device ID if it is not set
if not kodi.get_setting('deviceid'):
kb = xbmc.Keyboard('default', 'heading')
kb.setHeading('Enter your name or something so I know who you are \r\nand will allow you access to updates')
kb.setDefault('')
kb.setHiddenInput(False)
kb.doModal()
if (kb.isConfirmed()):
kb_input = kb.getText()
if (len(kb_input) > 3):
kodi.set_setting('deviceid', kb_input)
kodi.notify('Device ID set!', '['+kb_input+']')
else:
kodi.notify('Access denied!', 'Device ID not set.')
return
else:
kodi.notify('Access denied!', 'Device ID not set.')
return
params = getParams()
params['cv'] = current_version
kodi.debug('Config URL: '+kodi.get_setting('update_url'))
response = requests.get(kodi.get_setting('update_url'), params=params)
remote = json.loads(response.text)
kodi.debug(json.dumps(remote))
if kodi.get_setting('update_test') != 'true':
remote_version = remote['config_version']
url = remote['config_url']
else:
remote_version = remote['test_version']
url = remote['test_url']
response = requests.get(url+'.md5')
hash = response.text
kodi.debug('MD5 HASH: '+hash)
except Exception, e:
kodi.debug('getRemoteVersion: '+str(e))
dp.close()
kodi.debug('Remote Version: '+remote_version)
def updateKodi():
global remote
try:
# Prompt for Kodi Update
if kodi.get_setting('update_kodi') == 'true':
if kodi.platform() == 'android' and remote['kodi_version'] != kodi.get_version():
choice = xbmcgui.Dialog().yesno('idolpx Installer',
'A new version of Kodi is available!',
'Current version is [B]'+kodi.get_version()+'[/B].[CR]',
'Would you like to install version [B]'+remote['kodi_version'] +'[/B]?')
if choice == 1:
installer.installAPK(remote['kodi_url'])
except Exception, e:
kodi.debug('updateKodi: '+str(e))
def updateConfig():
global current, current_version, remote, remote_version, version_file, url, hash
try:
updateKodi()
# Is There an existing update.zip file ready to install?
update_file = xbmc.translatePath('special://home/update.zip')
if os.path.exists(update_file):
kodi.debug('Update File: '+update_file)
url = '/update.zip'
hash = ''
choice = xbmcgui.Dialog().yesno('idolpx Installer',
'An update file exists!',
'',
'Would you like to install this update?')
else:
if remote_version != current_version:
choice = xbmcgui.Dialog().yesno('idolpx Installer',
'A new configuration is available!',
'Current version is [B]'+current_version+'[/B].[CR]',
'Would you like to install version [COLOR green][B]'+remote_version+'[/B][/COLOR]?')
else:
choice = xbmcgui.Dialog().yesno('idolpx Installer',
'Current version is [B]'+current_version+'[/B].[CR]',
'Would you like to reinstall version [B]'+remote_version+'[/B]?')
if choice == 1:
# Give service enough time to stop downloading
time.sleep(3)
if installer.installConfig(url, hash):
# Save Installed Version to file
with open(version_file, "w") as outfile:
json.dump(remote, outfile)
# Adjust Advanced Settings
installer.adjust_advancedSettings()
choice = xbmcgui.Dialog().yesno('idolpx Installer',
'A restart is required. Would you like to restart Kodi now?')
if choice == 1:
kodi.kill()
xbmcgui.Dialog().ok('idolpx Installer',
'Update checks complete!')
else:
xbmcgui.Dialog().ok('idolpx Installer',
'Update canceled!')
except Exception, e:
kodi.debug('updateConfig: '+str(e))
def showAdult(status, pin='0'):
global window
if status == None:
status = window.getProperty('idolpx.installer.adultstatus')
if status == 'true':
# Enable Adult Addons
if pin == '0':
pin = xbmcgui.Dialog().numeric(0,'Enter PIN')
if pin == kodi.get_setting('adultpin'):
status = 'true'
else:
status = 'abort'
else:
# Disable Adult Addons
status = 'false'
kodi.debug('Adult Addons Enabled: ' + status)
if status != 'abort':
window.setProperty('idolpx.installer.adultstatus', status)
addonPath = xbmc.translatePath(os.path.join('special://home', 'addons'))
resourcePath = os.path.join(addonPath, kodi.addon_id(), 'resources')
nsfw_addons = os.path.join(resourcePath, 'nsfw_addons.dat')
with open(nsfw_addons, 'r') as myfile:
addons = myfile.read().split('\n')
for addon in addons:
try:
# Move Addon
if status == 'true':
shutil.move(os.path.join(resourcePath, addon), os.path.join(addonPath, addon))
#kodi.update_enabled(addon, 1)
else:
shutil.move(os.path.join(addonPath, addon), os.path.join(resourcePath, addon))
#kodi.update_enabled(addon, 0)
# Enable/Disable Addon
query = '{"jsonrpc":"2.0", "id":1, "method":"Addons.SetAddonEnabled","params":{"addonid":"%s", "enabled":%s}}' % (addon, status)
kodi.execute_jsonrpc(query)
kodi.debug(query)
xbmc.sleep(200)
except:
pass
kodi.execute('UpdateLocalAddons()')
kodi.execute('UpdateAddonRepos()')
#xbmc.sleep(1000)
#kodi.execute('ReloadSkin()')
kodi.set_setting('adultstatus', status)
if status == 'true':
kodi.notify('Adult Addons','Enabled!')
else:
kodi.notify('Adult Addons', 'Disabled!')
else:
kodi.notify('Adult Addons', 'Invalid PIN!')
def optimize():
installer.adjust_advancedSettings()
choice = xbmcgui.Dialog().yesno('idolpx Installer',
'A restart is required. Would you like to restart Kodi now?')
if choice == 1:
kodi.kill()
def backup():
choice = xbmcgui.Dialog().yesno(
'idolpx Installer',
'Backup Current Configuration?'
)
if choice == 1:
installer.createConfig()
if __name__ == '__main__':
kodi.debug(sys.argv)
arg = None
try:
arg = sys.argv[1].lower()
kodi.debug(arg)
except: pass
if arg == 'backup':
backup()
elif arg == 'optimize':
optimize()
elif arg == 'showadult':
showAdult(sys.argv[2].lower(), sys.argv[3].lower())
elif arg == 'updateKodi':
getLocalVersion()
getRemoteVersion()
updateKodi()
else:
if window.getProperty('idolpx.installer.running') == 'true':
kodi.debug('Addon is already running. Exiting...')
else:
window.setProperty('idolpx.installer.running', 'true')
getLocalVersion()
getRemoteVersion()
updateConfig()
window.clearProperty('idolpx.installer.running')