/[projects]/misc/xbmc/plugin.video.todic/default.py
ViewVC logotype

Contents of /misc/xbmc/plugin.video.todic/default.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3037 - (show annotations) (download) (as text)
Mon May 30 20:26:56 2016 UTC (7 years, 11 months ago) by torben
File MIME type: text/x-python
File size: 11667 byte(s)
1) switch to https, 2) use white for move discription
1
2 # This Python file uses the following encoding: utf-8
3
4 '''
5 Todic plugin for XBMC
6 Version 0.0.15
7 '''
8
9 import sys
10 import os
11
12
13 import xbmc
14 import xbmcaddon
15 import xbmcgui
16 import xbmcplugin
17 import urllib
18 import urllib2
19
20 # import pprint
21
22 from xml.dom.minidom import parseString
23
24 __addon__ = xbmcaddon.Addon(id='plugin.video.todic')
25 __key__ = __addon__.getSetting('xbmckey').lower()
26 __backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__
27 fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg')
28 datapath = xbmc.translatePath(
29 'special://profile/addon_data/plugin.video.todic/')
30
31 ADDON_PATH = __addon__.getAddonInfo('path')
32 SkinMasterPath = os.path.join(ADDON_PATH, 'skins') + '/'
33 MySkinPath = (os.path.join(SkinMasterPath, '720p')) + '/'
34 MySkin = 'main.xml'
35
36
37 class TodicMovieDialog(xbmcgui.WindowXMLDialog):
38
39 def __new__(cls):
40 return super(TodicMovieDialog, cls).__new__(cls, "main.xml", ADDON_PATH)
41
42 def __init__(self):
43 super(TodicMovieDialog, self).__init__()
44
45 def onClick(self, controlId):
46 print "OnClick: " + str(controlId)
47
48 if (controlId == 50):
49 self.close()
50 play_real_video(self.url, self.name)
51
52 if (controlId == 98):
53 self.close()
54
55 def onInit(self):
56
57 print "ONINIT"
58 self.getControl(1).setLabel(self.name)
59 self.getControl(2).setLabel(self.moviegroups)
60 self.getControl(3).setLabel(self.description)
61 self.getControl(10).setLabel(self.playlength)
62 self.getControl(11).setLabel(self.codecdetails)
63
64 orig_img_width = self.getControl(40).getWidth()
65 self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width
66 self.getControl(40).setWidth(int(self.starwidth))
67
68 def setUrl(self, url):
69 print "SETURL:" + url
70 self.url = url
71 self.fetchClipDetails()
72
73 def fetchClipDetails(self):
74 param1 = parse_parameter_string(self.url)
75
76 self.clipkey = param1["clipkey"]
77 print "CLIPKEY:" + self.clipkey
78 detailurl = __backend__ + "&action=clipdetails&clipkey=" + self.clipkey
79
80 xml = open_url(detailurl)
81
82 doc = parseString(xml)
83 self.imdbrating = getText(doc.getElementsByTagName("imdbrating"))
84 self.moviegroups = getText(doc.getElementsByTagName("moviegroups"))
85 self.playlength = getText(doc.getElementsByTagName("playlength"))
86 self.codecdetails = getText(doc.getElementsByTagName("codecdetails"))
87
88 def setName(self, name):
89 self.name = name
90
91 def setDescription(self, description):
92 self.description = description
93
94
95 class TodicPlayer(xbmc.Player):
96
97 def __init__(self, *args, **kwargs):
98 # xbmc.Player.__init__(selv,*args,**kwargs)
99 xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER)
100 self.stopped = False
101 self.started = False
102 print "[TodicPlayer] init"
103
104 # @catchall
105 def onPlayBackStarted(self):
106 self.started = True
107 print "[TodicPlayer] : started"
108 # super.onPlayBackStarted()
109
110 def onPlayBackStopped(self):
111 self.stopped = True
112 print "[TodicPlayer] : stopped"
113
114 def onPlayBackEnded(self):
115 self.stopped = True
116 print "[TodicPlayer] : ended"
117
118 def callbackLoop(self):
119 print "[Todic] startLoop"
120 while (self.stopped == False):
121 if (self.started == True):
122 print "[todic] " + str(self.getTime())
123 xbmc.sleep(5000)
124
125
126 def getText2(nodelist):
127 rc = []
128 for node in nodelist:
129 if node.nodeType == node.TEXT_NODE:
130 rc.append(node.data)
131 else:
132 rc.append(getText(node.childNodes))
133 return ''.join(rc)
134
135
136 def getText(nodelist):
137 if nodelist.length == 0:
138 return ''
139 else:
140 if nodelist[0].childNodes.length == 0:
141 return ''
142 else:
143 return nodelist[0].childNodes[0].nodeValue
144
145
146 def SaveFile(path, data):
147 file = open(path, 'w')
148 file.write(data)
149 file.close()
150
151
152 def open_url(url):
153 req = urllib2.Request(url)
154 content = urllib2.urlopen(req)
155 data = content.read()
156 content.close()
157 return data
158
159
160 def rootMenu():
161
162 msg = open_url(__backend__ + "&action=messages")
163 msg = msg.strip()
164
165 if msg != "":
166 dialog = xbmcgui.Dialog()
167 dialog.ok('XBMC Todic', msg)
168
169 buildList(__backend__, "", False) # call default list
170
171 # Adde xtra items to root menu
172 listitem = xbmcgui.ListItem(
173 label="Søg film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png')
174 listitem.setProperty('Fanart_Image', fanartImage)
175
176 u = sys.argv[0] + "?mode=10&name="
177 xbmcplugin.addDirectoryItem(
178 handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True)
179
180 # add search series
181 listitem = xbmcgui.ListItem(
182 label="Søg Serier ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png')
183 listitem.setProperty('Fanart_Image', fanartImage)
184
185 u = sys.argv[0] + "?mode=11&name="
186 xbmcplugin.addDirectoryItem(
187 handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True)
188
189 xbmcplugin.endOfDirectory(int(sys.argv[1]))
190
191
192 def buildList(url, title, endlist=True):
193 print '[TODIC]:' + str(url)
194
195 link = open_url(url)
196 doc = parseString(link)
197 ty = doc.getElementsByTagName("meta")[0].getAttribute("type")
198 print '[TODIC]' + str(ty)
199
200 if ty == 'clipList':
201 mode = '50'
202 folder = False
203 else:
204 mode = '1'
205 folder = True
206
207 entries = doc.getElementsByTagName("entry")
208 l = len(entries)
209 description = ''
210 for entry in entries:
211 name = getText(entry.getElementsByTagName("title"))
212 url = getText(entry.getElementsByTagName("url"))
213 thumb = getText(entry.getElementsByTagName("cover"))
214 description = getText(entry.getElementsByTagName("description"))
215 playcount = getText(entry.getElementsByTagName("playcount"))
216
217 if playcount == '':
218 playcount = '0'
219 playcount = int(playcount)
220
221 # print "name:" + name
222 # print "url:" + url
223 # print "thumb:" + thumb
224 # print "description:" + description
225 listitem = xbmcgui.ListItem(
226 label=name, label2='test', iconImage='DefaultFolder.png', thumbnailImage=thumb)
227 listitem.setProperty('Fanart_Image', fanartImage)
228 if mode == '50':
229 infoLabels = {}
230 infoLabels['title'] = name
231 infoLabels['plot'] = description
232 infoLabels['playcount'] = playcount
233 listitem.setInfo('video', infoLabels)
234
235 name = name.encode('UTF-8')
236 description = description.encode('UTF-8')
237
238 u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(
239 name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description)
240 xbmcplugin.addDirectoryItem(
241 handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=folder, totalItems=l)
242
243 if (endlist == True):
244 xbmcplugin.endOfDirectory(int(sys.argv[1]))
245
246
247 def play_video(url, name, description):
248 if (description == None or description == ""):
249 play_real_video(url, name)
250 else:
251 d = TodicMovieDialog()
252 d.setUrl(url)
253 d.setName(name)
254 d.setDescription(description)
255
256 d.doModal()
257
258
259 def play_real_video(url, name):
260 xml = open_url(url)
261 print 'TODIC url: ' + str(url)
262 print 'TODIC xml: ' + xml
263
264 doc = parseString(xml)
265 url = getText(doc.getElementsByTagName("url"))
266
267 subtitleurl = getText(doc.getElementsByTagName("subtitles"))
268 subtitlesfile = os.path.join(datapath, 'temp.srt')
269
270 # if old srt file exists delete it first
271 if os.path.isfile(subtitlesfile):
272 os.unlink(subtitlesfile)
273
274 print '[TODIC] subs: ' + str(subtitleurl)
275 if len(subtitleurl) > 0:
276 subtitles = open_url(subtitleurl)
277 SaveFile(subtitlesfile, subtitles)
278 print 'TODIC downloaded subtitles'
279
280 image = xbmc.getInfoImage('ListItem.Thumb')
281 listitem = xbmcgui.ListItem(
282 label=name, iconImage='DefaultVideo.png', thumbnailImage=image)
283 listitem.setInfo(type="Video", infoLabels={"Title": name})
284
285 player = TodicPlayer(xbmc.PLAYER_CORE_AUTO)
286 player.play(str(url), listitem)
287
288 # kan ikke loade subtitles hvis foerend playeren koerer
289 count = 0
290 while not xbmc.Player().isPlaying():
291 xbmc.sleep(500)
292 count += 1
293 if count > 10:
294 break
295
296 if xbmc.Player().isPlaying():
297 if os.path.isfile(subtitlesfile):
298 player.setSubtitles(subtitlesfile)
299 print 'TODIC started subtitles'
300 else:
301 player.disableSubtitles()
302
303 # player.callbackLoop()
304
305
306 def search():
307 search = getUserInput("Todic Søgning")
308
309 if (search != None and search != ""):
310 url = __backend__ + "&action=search&search=" + \
311 urllib.quote_plus(search)
312
313 # print "[TODIC] Search start: " + search
314 # print "[TODIC] Search url: " + url
315
316 buildList(url, "søgning")
317
318
319 def searchSeries():
320 search = getUserInput("Todic Serie Søgning")
321
322 if (search != None and search != ""):
323 url = __backend__ + "&action=searchseries&search=" + \
324 urllib.quote_plus(search)
325
326 # print "[TODIC] Search start: " + search
327 # print "[TODIC] Search url: " + url
328
329 buildList(url, "serie søgning")
330
331
332 #=================================== Tool Box =======================================
333 # shows a more userfriendly notification
334 def showMessage(heading, message):
335 duration = 15 * 1000
336 xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' %
337 (heading, message, duration))
338
339
340 # raise a keyboard for user input
341 def getUserInput(title="Input", default="", hidden=False):
342 result = None
343
344 # Fix for when this functions is called with default=None
345 if not default:
346 default = ""
347
348 keyboard = xbmc.Keyboard(default, title)
349 keyboard.setHiddenInput(hidden)
350 keyboard.doModal()
351
352 if keyboard.isConfirmed():
353 result = keyboard.getText()
354
355 return result
356
357
358 def get_params():
359 return parse_parameter_string(sys.argv[2])
360
361
362 def parse_parameter_string(paramstring):
363 param = []
364 if len(paramstring) >= 2:
365 params = paramstring
366 cleanedparams = params.replace('?', '')
367 if (params[len(params) - 1] == '/'):
368 params = params[0:len(params) - 2]
369 pairsofparams = cleanedparams.split('&')
370 param = {}
371 for i in range(len(pairsofparams)):
372 splitparams = {}
373 splitparams = pairsofparams[i].split('=')
374 if (len(splitparams)) == 2:
375 param[splitparams[0]] = splitparams[1]
376 return param
377
378
379 params = get_params()
380 url = None
381 name = None
382 mode = None
383 description = None
384
385 try:
386 url = urllib.unquote_plus(params["url"])
387 except:
388 pass
389 try:
390 name = urllib.unquote_plus(params["name"])
391 except:
392 pass
393 try:
394 mode = int(params["mode"])
395 except:
396 pass
397 try:
398 description = urllib.unquote_plus(params["description"])
399 except:
400 pass
401
402 try:
403 open_url("http://todic.dk")
404 except:
405 showMessage("Fejl", "Kunne ikke forbinde til todic.dk")
406 exit()
407
408
409 if url == 'refresh':
410 # xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker
411 # ikke med XBMC12
412 xbmc.executebuiltin("Container.Refresh")
413
414
415 elif mode == None:
416 # build main menu
417 rootMenu()
418
419 elif mode == 1:
420 # build list of movie starting letters
421 buildList(url, name)
422
423 elif mode == 10:
424 search()
425
426 elif mode == 11:
427 searchSeries()
428
429
430 elif mode == 50:
431 play_video(url, name, description)

  ViewVC Help
Powered by ViewVC 1.1.20