-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathxstream.py
341 lines (315 loc) · 13.4 KB
/
xstream.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# -*- coding: utf-8 -*-
from resources.lib.handler.ParameterHandler import ParameterHandler
from resources.lib.handler.requestHandler import cRequestHandler
from resources.lib.handler.pluginHandler import cPluginHandler
from resources.lib.tools import logger
from resources.lib.gui.guiElement import cGuiElement
from resources.lib.gui.gui import cGui
from resources.lib.config import cConfig
import sys, xbmc, xbmcgui
def run():
parseUrl()
def viewInfo(params):
from resources.lib.tmdbinfo import WindowsBoxes
parms = ParameterHandler()
sCleanTitle = params.getValue('searchTitle')
sMeta = parms.getValue('sMeta')
sYear = parms.getValue('sYear')
WindowsBoxes(sCleanTitle, sCleanTitle, sMeta, sYear)
def parseUrl():
params = ParameterHandler()
logger.info(params.getAllParameters())
# If no function is set, we set it to the default "load" function
if params.exist('function'):
sFunction = params.getValue('function')
if sFunction == 'spacer':
return True
elif sFunction == 'clearCache':
cRequestHandler('dummy').clearCache()
return
elif sFunction == 'viewInfo':
viewInfo(params)
return
elif sFunction == 'searchAlter':
searchAlter(params)
return
elif sFunction == 'searchTMDB':
searchTMDB(params)
return
elif sFunction == 'devUpdates':
from resources.lib import updateManager
updateManager.devUpdates()
return
elif params.exist('remoteplayurl'):
try:
import urlresolver
remotePlayUrl = params.getValue('remoteplayurl')
sLink = urlresolver.resolve(remotePlayUrl)
if sLink:
xbmc.executebuiltin('PlayMedia(' + sLink + ')')
else:
logger.info("Could not play remote url '%s'" % sLink)
except urlresolver.resolver.ResolverError as e:
logger.error('ResolverError: %s' % e)
return
else:
sFunction = 'load'
# Test if we should run a function on a special site
if not params.exist('site'):
xbmc.executebuiltin('RunPlugin(%s?function=clearCache)' % sys.argv[0])
# As a default if no site was specified, we run the default starting gui with all plugins
showMainMenu(sFunction)
return
sSiteName = params.getValue('site')
if params.exist('playMode'):
from resources.lib.gui.hoster import cHosterGui
url = False
playMode = params.getValue('playMode')
isHoster = params.getValue('isHoster')
url = params.getValue('url')
manual = params.exist('manual')
if cConfig().getSetting('hosterSelect') == 'Auto' and playMode != 'jd' and playMode != 'jd2' and playMode != 'pyload' and not manual:
cHosterGui().streamAuto(playMode, sSiteName, sFunction)
else:
cHosterGui().stream(playMode, sSiteName, sFunction, url)
return
logger.info("Call function '%s' from '%s'" % (sFunction, sSiteName))
# If the hoster gui is called, run the function on it and return
if sSiteName == 'cHosterGui':
showHosterGui(sFunction)
# If global search is called
elif sSiteName == 'globalSearch':
searchterm = False
if params.exist('searchterm'):
searchterm = params.getValue('searchterm')
searchGlobal(searchterm)
elif sSiteName == 'xStream':
oGui = cGui()
oGui.openSettings()
oGui.updateDirectory()
# If the urlresolver settings are called
elif sSiteName == 'urlresolver':
import urlresolver
urlresolver.display_settings()
# If UpdateManager are called (manual update)
elif sSiteName == 'devUpdates':
from resources.lib import updateManager
updateManager.devUpdates()
elif sSiteName == 'settings':
oGui = cGui()
for folder in settingsGuiElements():
oGui.addFolder(folder)
oGui.setEndOfDirectory()
else:
# Else load any other site as plugin and run the function
plugin = __import__(sSiteName, globals(), locals())
function = getattr(plugin, sFunction)
function()
def showMainMenu(sFunction):
oGui = cGui()
if cConfig().getSetting('GlobalSearchPosition') == 'true':
oGui.addFolder(globalSearchGuiElement())
oPluginHandler = cPluginHandler()
aPlugins = oPluginHandler.getAvailablePlugins()
if not aPlugins:
logger.info('No activated Plugins found')
# Open the settings dialog to choose a plugin that could be enabled
oGui.openSettings()
oGui.updateDirectory()
else:
# Create a gui element for every plugin found
for aPlugin in sorted(aPlugins, key=lambda k: k['id']):
oGuiElement = cGuiElement()
oGuiElement.setTitle(aPlugin['name'])
oGuiElement.setSiteName(aPlugin['id'])
oGuiElement.setFunction(sFunction)
if 'icon' in aPlugin and aPlugin['icon']:
oGuiElement.setThumbnail(aPlugin['icon'])
oGui.addFolder(oGuiElement)
if cConfig().getSetting('GlobalSearchPosition') == 'false':
oGui.addFolder(globalSearchGuiElement())
if cConfig().getSetting('SettingsFolder') == 'true':
# Create a gui element for Settingsfolder
oGuiElement = cGuiElement()
oGuiElement.setTitle(cConfig().getLocalizedString(30041))
oGuiElement.setSiteName('settings')
oGuiElement.setFunction('showSettingsFolder')
oGuiElement.setThumbnail('DefaultAddonService.png')
oGui.addFolder(oGuiElement)
else:
for folder in settingsGuiElements():
oGui.addFolder(folder)
# ka add - Create a gui element for updateManager
if cConfig().getSetting('DevUpdateAuto') == 'false':
oGuiElement = cGuiElement()
oGuiElement.setTitle('Nightly Update')
oGuiElement.setSiteName('devUpdates')
oGuiElement.setFunction(sFunction)
oGuiElement.setThumbnail('DefaultAddonProgram.png')
oGui.addFolder(oGuiElement)
oGui.setEndOfDirectory()
def settingsGuiElements():
# Create a gui element for addon settings
oGuiElement = cGuiElement()
oGuiElement.setTitle(cConfig().getLocalizedString(30042))
oGuiElement.setSiteName('xStream')
oGuiElement.setFunction('display_settings')
oGuiElement.setThumbnail('DefaultAddonProgram.png')
xStreamSettings = oGuiElement
# Create a gui element for urlresolver settings
oGuiElement = cGuiElement()
oGuiElement.setTitle(cConfig().getLocalizedString(30043))
oGuiElement.setSiteName('urlresolver')
oGuiElement.setFunction('display_settings')
oGuiElement.setThumbnail('DefaultAddonRepository.png')
urlResolverSettings = oGuiElement
return xStreamSettings, urlResolverSettings
def globalSearchGuiElement():
# Create a gui element for global search
oGuiElement = cGuiElement()
oGuiElement.setTitle(cConfig().getLocalizedString(30040))
oGuiElement.setSiteName('globalSearch')
oGuiElement.setFunction('globalSearch')
oGuiElement.setThumbnail('DefaultAddonWebSkin.png')
return oGuiElement
def showHosterGui(sFunction):
from resources.lib.gui.hoster import cHosterGui
oHosterGui = cHosterGui()
function = getattr(oHosterGui, sFunction)
function()
return True
def searchGlobal(sSearchText=False):
import threading
oGui = cGui()
oGui.globalSearch = True
oGui._collectMode = True
if not sSearchText:
sSearchText = oGui.showKeyBoard()
if not sSearchText: return True
aPlugins = []
aPlugins = cPluginHandler().getAvailablePlugins()
dialog = xbmcgui.DialogProgress()
dialog.create('xStream', 'Searching...')
numPlugins = len(aPlugins)
threads = []
for count, pluginEntry in enumerate(aPlugins):
if not pluginEntry['globalsearch']:
continue
dialog.update((count + 1) * 50 // numPlugins, 'Searching: ' + str(pluginEntry['name']) + '...')
if sys.version_info[0] == 2:
logger.info('Searching for %s at %s' % (sSearchText.decode('utf-8'), pluginEntry['id']))
else:
logger.info('Searching for %s at %s' % (sSearchText, pluginEntry['id']))
t = threading.Thread(target=_pluginSearch, args=(pluginEntry, sSearchText, oGui), name=pluginEntry['name'])
threads += [t]
t.start()
for count, t in enumerate(threads):
t.join()
dialog.update((count + 1) * 50 // numPlugins + 50, t.getName() + ' returned')
dialog.close()
# deactivate collectMode attribute because now we want the elements really added
oGui._collectMode = False
total = len(oGui.searchResults)
dialog = xbmcgui.DialogProgress()
dialog.create('xStream', 'Gathering info...')
for count, result in enumerate(sorted(oGui.searchResults, key=lambda k: k['guiElement'].getSiteName()), 1):
oGui.addFolder(result['guiElement'], result['params'], bIsFolder=result['isFolder'], iTotal=total)
dialog.update(count * 100 // total, str(count) + ' of ' + str(total) + ': ' + result['guiElement'].getTitle())
dialog.close()
oGui.setView()
oGui.setEndOfDirectory()
return True
def searchAlter(params):
searchTitle = params.getValue('searchTitle')
searchImdbId = params.getValue('searchImdbID')
searchYear = params.getValue('searchYear')
import threading
oGui = cGui()
oGui.globalSearch = True
oGui._collectMode = True
aPlugins = []
aPlugins = cPluginHandler().getAvailablePlugins()
dialog = xbmcgui.DialogProgress()
dialog.create('xStream', "Searching...")
numPlugins = len(aPlugins)
threads = []
for count, pluginEntry in enumerate(aPlugins):
dialog.update((count + 1) * 50 // numPlugins, 'Searching: ' + str(pluginEntry['name']) + '...')
if sys.version_info[0] == 2:
logger.info('Searching for ' + searchTitle + pluginEntry['id'].encode('utf-8'))
else:
logger.info('Searching for ' + searchTitle + pluginEntry['id'])
t = threading.Thread(target=_pluginSearch, args=(pluginEntry, searchTitle, oGui), name=pluginEntry['name'])
threads += [t]
t.start()
for count, t in enumerate(threads):
t.join()
dialog.update((count + 1) * 50 // numPlugins + 50, t.getName() + ' returned')
dialog.close()
# check results, put this to the threaded part, too
filteredResults = []
for result in oGui.searchResults:
guiElement = result['guiElement']
logger.info('Site: %s Titel: %s' % (guiElement.getSiteName(), guiElement.getTitle()))
if searchTitle not in guiElement.getTitle():
continue
if guiElement._sYear and searchYear and guiElement._sYear != searchYear: continue
if searchImdbId and guiElement.getItemProperties().get('imdbID', False) and guiElement.getItemProperties().get('imdbID', False) != searchImdbId: continue
filteredResults.append(result)
oGui._collectMode = False
total = len(filteredResults)
for result in sorted(filteredResults, key=lambda k: k['guiElement'].getSiteName()):
oGui.addFolder(result['guiElement'], result['params'], bIsFolder=result['isFolder'], iTotal=total)
oGui.setView()
oGui.setEndOfDirectory()
xbmc.executebuiltin('Container.Update')
return True
def searchTMDB(params):
sSearchText = params.getValue('searchTitle')
import threading
oGui = cGui()
oGui.globalSearch = True
oGui._collectMode = True
if not sSearchText: return True
aPlugins = []
aPlugins = cPluginHandler().getAvailablePlugins()
dialog = xbmcgui.DialogProgress()
dialog.create('xStream', 'Searching...')
numPlugins = len(aPlugins)
threads = []
for count, pluginEntry in enumerate(aPlugins):
if not pluginEntry['globalsearch']:
continue
dialog.update((count + 1) * 50 // numPlugins, 'Searching: ' + str(pluginEntry['name']) + '...')
if sys.version_info[0] == 2:
logger.info('Searching for %s at %s' % (sSearchText.decode('utf-8'), pluginEntry['id']))
else:
logger.info('Searching for %s at %s' % (sSearchText, pluginEntry['id']))
t = threading.Thread(target=_pluginSearch, args=(pluginEntry, sSearchText, oGui), name=pluginEntry['name'])
threads += [t]
t.start()
for count, t in enumerate(threads):
t.join()
dialog.update((count + 1) * 50 // numPlugins + 50, t.getName() + ' returned')
dialog.close()
# deactivate collectMode attribute because now we want the elements really added
oGui._collectMode = False
total = len(oGui.searchResults)
dialog = xbmcgui.DialogProgress()
dialog.create('xStream', 'Gathering info...')
for count, result in enumerate(sorted(oGui.searchResults, key=lambda k: k['guiElement'].getSiteName()), 1):
oGui.addFolder(result['guiElement'], result['params'], bIsFolder=result['isFolder'], iTotal=total)
dialog.update(count * 100 // total, str(count) + ' of ' + str(total) + ': ' + result['guiElement'].getTitle())
dialog.close()
oGui.setView()
oGui.setEndOfDirectory()
return True
def _pluginSearch(pluginEntry, sSearchText, oGui):
try:
plugin = __import__(pluginEntry['id'], globals(), locals())
function = getattr(plugin, '_search')
function(oGui, sSearchText)
except:
logger.error(pluginEntry['name'] + ': search failed')
import traceback
logger.debug(traceback.format_exc())