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

  ViewVC Help
Powered by ViewVC 1.1.20