/[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 2595 - (hide 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 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 2593 Version 0.0.14
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 2595 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     def setUrl( self, url):
65 torben 2595 print "SETURL:" + url
66 torben 2592 self.url = url
67 torben 2595 self.fetchClipDetails()
68 torben 2592
69 torben 2595
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 torben 2592 def setName( self, name ):
88     self.name = name
89    
90     def setDescription( self, description ):
91     self.description = description
92    
93    
94 torben 1676 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 torben 1678 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 torben 1676
133 torben 1678 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 torben 1676
142 torben 1914 def SaveFile(path, data):
143     file = open(path,'w')
144     file.write(data)
145     file.close()
146 torben 1678
147 torben 1914
148 torben 1629 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 torben 1648
157 torben 1799 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 torben 1659 buildList(__backend__, "", False) # call default list
165 torben 1631
166 torben 1649 # Adde xtra items to root menu
167 torben 1640 listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
168 torben 1648 listitem.setProperty('Fanart_Image', fanartImage)
169    
170 torben 1649 u = sys.argv[0] + "?mode=10&name="
171     ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)
172 torben 1631
173 torben 2097 #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 torben 1629 xbmcplugin.endOfDirectory(int(sys.argv[1]))
181    
182    
183 torben 1659 def buildList(url,title, endlist=True):
184 torben 1914 print '[TODIC]:'+str(url)
185 torben 1678
186 torben 1629 link = open_url(url)
187 torben 1678 doc = parseString(link)
188     ty = doc.getElementsByTagName("meta")[0].getAttribute("type")
189     print '[TODIC]'+str(ty)
190 torben 1646
191 torben 1678 if ty == 'clipList':
192 torben 1646 mode = '50'
193     folder = False
194     else:
195     mode = '1'
196     folder = True
197    
198 torben 1829
199 torben 1678 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 torben 1830 playcount = getText( entry.getElementsByTagName("playcount") )
208 torben 1647
209 torben 1830 if playcount == '':
210     playcount = '0'
211     playcount = int(playcount)
212    
213 torben 1678
214     ## print "name:" + name
215     # print "url:" + url
216     # print "thumb:" + thumb
217     # print "description:" + description
218    
219    
220 torben 1647 listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
221 torben 1648 listitem.setProperty('Fanart_Image', fanartImage)
222 torben 1650 if mode == '50':
223     infoLabels = {}
224     infoLabels['title'] = name
225 torben 1829 infoLabels['plot'] = description
226     infoLabels['playcount'] = playcount
227 torben 1650 listitem.setInfo('video', infoLabels)
228 torben 1648
229 torben 1923 name = name.encode('UTF-8')
230     description = description.encode('UTF-8')
231    
232    
233 torben 2592 u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description)
234 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
235 torben 1629
236 torben 1659 if (endlist == True):
237     xbmcplugin.endOfDirectory(int(sys.argv[1]))
238 torben 1629
239    
240    
241 torben 1659
242 torben 2592 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 torben 1914 print 'TODIC url: ' + str(url)
257     print 'TODIC xml: '+ xml
258 torben 1678
259     doc = parseString(xml)
260     url = getText( doc.getElementsByTagName("url") )
261    
262 torben 1914 subtitleurl = getText( doc.getElementsByTagName("subtitles") )
263     subtitlesfile = os.path.join(datapath,'temp.srt')
264    
265 torben 1917 #if old srt file exists delete it first
266     if os.path.isfile(subtitlesfile):
267     os.unlink(subtitlesfile)
268    
269 torben 1914 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 torben 1629 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 torben 1676 player = TodicPlayer(xbmc.PLAYER_CORE_AUTO)
282     player.play(str(url), listitem)
283 torben 1914
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 torben 1917 else:
298     player.disableSubtitles()
299 torben 1914
300 torben 1678 # player.callbackLoop()
301 torben 1676
302    
303    
304 torben 1631 def search():
305     search = getUserInput("Todic Søgning")
306 torben 1629
307 torben 1634 if (search != None and search != ""):
308     url = __backend__ + "&action=search&search=" + urllib.quote_plus(search)
309 torben 1631
310 torben 1634 #print "[TODIC] Search start: " + search
311     #print "[TODIC] Search url: " + url
312 torben 1631
313 torben 1646 buildList(url, "søgning")
314 torben 1631
315 torben 2097 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 torben 1631
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 torben 1629 def get_params():
356 torben 2595 return parse_parameter_string( sys.argv[2] )
357    
358     def parse_parameter_string( paramstring ):
359 torben 1629 param=[]
360     if len(paramstring)>=2:
361 torben 2595 params = paramstring
362 torben 1629 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 torben 2592 description = None
380 torben 1629
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 torben 2592 try:
394     description = urllib.unquote_plus(params["description"])
395     except:
396     pass
397 torben 1629
398 torben 2440 try:
399     open_url("http://todic.dk")
400     except:
401     showMessage("Fejl", "Kunne ikke forbinde til todic.dk")
402     exit()
403    
404    
405 torben 1814 if url == 'refresh':
406 torben 1972 #xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12
407 torben 1814 xbmc.executebuiltin("Container.Refresh")
408    
409 torben 1629
410 torben 1814 elif mode == None:
411 torben 1629 #build main menu
412     rootMenu()
413    
414     elif mode == 1:
415     #build list of movie starting letters
416     buildList(url, name)
417    
418 torben 1631 elif mode == 10:
419     search()
420 torben 2097
421     elif mode == 11:
422     searchSeries()
423 torben 1631
424    
425 torben 1629 elif mode == 50:
426 torben 2592 play_video(url, name, description)

  ViewVC Help
Powered by ViewVC 1.1.20