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

  ViewVC Help
Powered by ViewVC 1.1.20