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

  ViewVC Help
Powered by ViewVC 1.1.20