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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20