forked from Phhere/plugin.video.xstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxstream.py
299 lines (277 loc) · 10.7 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
# -*- coding: utf-8 -*-
from resources.lib.handler.pluginHandler import cPluginHandler
from resources.lib.handler.ParameterHandler import ParameterHandler
from resources.lib.gui.gui import cGui
from resources.lib.gui.guiElement import cGuiElement
from resources.lib.config import cConfig
from resources.lib import logger
import xbmc
import xbmcgui
import sys
# Main starting function
def run():
parseUrl()
def changeWatched(params):
if not cConfig().getSetting('metahandler')=='true':
return
#videoType, name, imdbID, season=season, episode=episode, year=year, watched=watched
try:
from metahandler import metahandlers
meta = metahandlers.MetaData()
season = ''
episode = ''
mediaType = params.getValue('mediaType')
imdbID = params.getValue('imdbID')
name = params.getValue('title')
if params.exist('season'):
season = params.getValue('season')
if params.exist('episode'):
episode = params.getValue('episode')
if imdbID:
meta.change_watched(mediaType, name, imdbID, season=season, episode=episode)
xbmc.executebuiltin("XBMC.Container.Refresh")
except Exception as e:
META = False
logger.info("Could not import package 'metahandler'")
logger.info(e)
return
def updateMeta(params):
if not cConfig().getSetting('metahandler')=='true':
return
#videoType, name, imdbID, season=season, episode=episode, year=year, watched=watched
try:
from metahandler import metahandlers
except Exception as e:
logger.info("Could not import package 'metahandler'")
logger.info(e)
return
meta = metahandlers.MetaData()
season = ''
episode = ''
mediaType = params.getValue('mediaType')
imdbID = params.getValue('imdbID')
name = str(params.getValue('title'))
year = params.getValue('year')
print "MedienType: "+mediaType
if (mediaType == 'movie' or mediaType == 'tvshow') :
# show meta search input
oGui = cGui()
sSearchText = oGui.showKeyBoard(name)
if (sSearchText != False and sSearchText != ''):
if mediaType == 'movie':
try:
foundInfo = meta.search_movies(sSearchText)
except:
logger.info('error or nothing found')
foundInfo = False
elif mediaType == 'tvshow':
foundInfo = metahandlers.TheTVDB().get_matching_shows(sSearchText, language="all")
else:
return
else:
return
if not foundInfo:
oGui.showInfo('xStream', 'Suchanfrage lieferte kein Ergebnis')
return
# select possible match
dialog = xbmcgui.Dialog()
items = []
for item in foundInfo:
if mediaType == 'movie':
items.append(str(item['title'].encode('utf-8'))+' ('+str(item['year'])+')')
elif mediaType == 'tvshow':
items.append(str(item[1]))
else:
return
index = dialog.select('Film/Serie wählen', items)
if index > -1:
item = foundInfo[index]
else:
return False
if not imdbID:
imdbID = ''
if not year:
year = ''
if mediaType == 'movie':
meta.update_meta(mediaType, name, imdbID, new_imdb_id=str(item['imdb_id']), new_tmdb_id=str(item['tmdb_id']), year=year)
elif mediaType == 'tvshow':
if params.exist('season'):
season = params.getValue('season')
meta.update_season(name, imdbID, season)
if params.exist('episode'):
episode = params.getValue('episode')
if season and episode:
meta.update_episode_meta(name, imdbID, season, episode)
elif season:
meta.update_season(name, imdbID, season)
else:
meta.update_meta(mediaType, name, imdbID, new_imdb_id=str(item[2]), new_tmdb_id=str(item[0]), year=year)
#print params.getAllParameters()
xbmc.executebuiltin("XBMC.Container.Refresh")
return
def parseUrl():
params = ParameterHandler()
# 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':
from resources.lib.handler.requestHandler import cRequestHandler
cRequestHandler('dummy').clearCache()
return
elif sFunction == 'changeWatched':
changeWatched(params)
return
elif sFunction == 'updateMeta':
updateMeta(params)
return
else:
sFunction = 'load'
# Test if we should run a function on a special site
if params.exist('site'):
sSiteName = params.getValue('site')
logger.info (params.getAllParameters())
if params.exist('playMode'):
from resources.lib.gui.hoster import cHosterGui
url = False
playMode = params.getValue('playMode')
isHoster = params.getValue('isHoster')
if isHoster == 'true':
url = params.getValue('url')
if cConfig().getSetting('autoPlay')=='true' and playMode != 'jd' and playMode != 'pyload':
cHosterGui().streamAuto(playMode, sSiteName, sFunction)
else:
cHosterGui().stream(playMode, sSiteName, sFunction, url)
return
else:
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)
return
# If global search is called
elif sSiteName == 'globalSearch':
searchGlobal()
return
elif sSiteName == 'favGui':
showFavGui(sFunction)
return
# If addon settings are called
elif sSiteName == 'xStream':
oGui = cGui()
oGui.openSettings()
oGui.updateDirectory()
return
# If the urlresolver settings are called
elif sSiteName == 'urlresolver':
import urlresolver
urlresolver.display_settings()
return
# If metahandler settings are called
elif sSiteName == 'metahandler':
import metahandler
metahandler.display_settings()
return
else:
# Else load any other site as plugin and run the function
plugin = __import__(sSiteName, globals(), locals())
function = getattr(plugin, sFunction)
function()
else:
xbmc.executebuiltin('XBMC.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)
def showMainMenu(sFunction):
oGui = cGui()
oPluginHandler = cPluginHandler()
aPlugins = oPluginHandler.getAvailablePlugins()
if len(aPlugins) <= 0:
logger.info("No Plugins found")
# Open the settings dialog to choose a plugin that could be enable
oGui.openSettings()
oGui.updateDirectory()
else:
# Create a gui element for every plugin found
for aPlugin in aPlugins:
oGuiElement = cGuiElement()
oGuiElement.setTitle(aPlugin['name'])
oGuiElement.setSiteName(aPlugin['id'])
oGuiElement.setFunction(sFunction)
if aPlugin['icon'] != '':
oGuiElement.setThumbnail(aPlugin['icon'])
oGui.addFolder(oGuiElement)
# Create a gui element for global search
oGuiElement = cGuiElement()
oGuiElement.setTitle("Globale Suche")
oGuiElement.setSiteName("globalSearch")
oGuiElement.setFunction("globalSearch")
#oGuiElement.setThumbnail("DefaultAddonService.png")
oGui.addFolder(oGuiElement)
# Create a gui element for favorites
#oGuiElement = cGuiElement()
#oGuiElement.setTitle("Favorites")
#oGuiElement.setSiteName("FavGui")
#oGuiElement.setFunction("showFavs")
#oGuiElement.setThumbnail("DefaultAddonService.png")
#oGui.addFolder(oGuiElement)
# Create a gui element for addon settings
oGuiElement = cGuiElement()
oGuiElement.setTitle("xStream Settings")
oGuiElement.setSiteName("xStream")
oGuiElement.setFunction("display_settings")
oGuiElement.setThumbnail("DefaultAddonService.png")
oGui.addFolder(oGuiElement)
# Create a gui element for urlresolver settings
oGuiElement = cGuiElement()
oGuiElement.setTitle("Resolver Settings")
oGuiElement.setSiteName("urlresolver")
oGuiElement.setFunction("display_settings")
oGuiElement.setThumbnail("DefaultAddonService.png")
oGui.addFolder(oGuiElement)
if cConfig().getSetting('metahandler')=='true':
# Create a gui element for metahandler settings
oGuiElement = cGuiElement()
oGuiElement.setTitle("Metahandler Settings")
oGuiElement.setSiteName("metahandler")
oGuiElement.setFunction("display_settings")
oGuiElement.setThumbnail("DefaultAddonService.png")
oGui.addFolder(oGuiElement)
oGui.setEndOfDirectory()
def showHosterGui(sFunction):
from resources.lib.gui.hoster import cHosterGui
oHosterGui = cHosterGui()
function = getattr(oHosterGui, sFunction)
function()
return True
#def showFavGui(functionName):
#from resources.lib.gui.favorites import FavGui
#oFavGui = FavGui()
#function = getattr(oFavGui, functionName)
#function()
#return True
def searchGlobal():
oGui = cGui()
sSearchText = oGui.showKeyBoard()
if (sSearchText != False and sSearchText != ''):
aPlugins = []
aPlugins = cPluginHandler().getAvailablePlugins()
for pluginEntry in aPlugins:
pluginName = str(pluginEntry['name'])
pluginSiteName = pluginEntry['id']
logger.info('Searching for "'+sSearchText+'" at '+pluginName)
try:
plugin = __import__(pluginSiteName, globals(), locals())
function = getattr(plugin, '_search')
oGuiElement = cGuiElement('[B][COLOR yellow]----'+pluginName+'----[/COLOR][/B]',pluginSiteName,'spacer')
if len(pluginEntry)>2:
oGuiElement.setThumbnail(pluginEntry['icon'])
oGui.addFolder(oGuiElement)
function(oGui, sSearchText)
except:
logger.info(pluginName+': search failed')
import traceback
print traceback.format_exc()
oGui.setView()
oGui.setEndOfDirectory()
return True