/[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 1914 - (hide annotations) (download) (as text)
Thu Jan 17 18:44:47 2013 UTC (11 years, 4 months ago) by torben
File MIME type: text/x-python
File size: 7363 byte(s)
add support for subtitles
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     Version 0.0.2
7     '''
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 1676
30     class TodicPlayer(xbmc.Player):
31     def __init__(self, *args, **kwargs):
32     #xbmc.Player.__init__(selv,*args,**kwargs)
33     xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER )
34     self.stopped = False
35     self.started = False
36     print "[TodicPlayer] init"
37    
38     # @catchall
39     def onPlayBackStarted(self):
40     self.started = True
41     print "[TodicPlayer] : started"
42     # super.onPlayBackStarted()
43    
44     def onPlayBackStopped(self):
45     self.stopped = True
46     print "[TodicPlayer] : stopped"
47    
48     def onPlayBackEnded(self):
49     self.stopped = True
50     print "[TodicPlayer] : ended"
51    
52     def callbackLoop(self):
53     print "[Todic] startLoop"
54     while (self.stopped == False):
55     if (self.started == True ):
56     print "[todic] " + str(self.getTime())
57     xbmc.sleep(5000)
58    
59    
60 torben 1678 def getText2(nodelist):
61     rc = []
62     for node in nodelist:
63     if node.nodeType == node.TEXT_NODE:
64     rc.append(node.data)
65     else:
66     rc.append( getText(node.childNodes) )
67     return ''.join(rc)
68 torben 1676
69 torben 1678 def getText(nodelist):
70     if nodelist.length == 0:
71     return ''
72     else:
73     if nodelist[0].childNodes.length == 0:
74     return ''
75     else:
76     return nodelist[0].childNodes[0].nodeValue
77 torben 1676
78 torben 1914 def SaveFile(path, data):
79     file = open(path,'w')
80     file.write(data)
81     file.close()
82 torben 1678
83 torben 1914
84 torben 1629 def open_url(url):
85     req = urllib2.Request(url)
86     content = urllib2.urlopen(req)
87     data = content.read()
88     content.close()
89     return data
90    
91     def rootMenu():
92 torben 1648
93 torben 1799 msg = open_url(__backend__ + "&action=messages")
94     msg = msg.strip()
95    
96     if msg != "":
97     dialog = xbmcgui.Dialog()
98     dialog.ok('XBMC Todic', msg)
99    
100 torben 1659 buildList(__backend__, "", False) # call default list
101 torben 1631
102 torben 1649 # Adde xtra items to root menu
103 torben 1640 listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
104 torben 1648 listitem.setProperty('Fanart_Image', fanartImage)
105    
106 torben 1649 u = sys.argv[0] + "?mode=10&name="
107     ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)
108 torben 1631
109 torben 1629 xbmcplugin.endOfDirectory(int(sys.argv[1]))
110    
111    
112 torben 1659 def buildList(url,title, endlist=True):
113 torben 1914 print '[TODIC]:'+str(url)
114 torben 1678
115 torben 1629 link = open_url(url)
116 torben 1678 doc = parseString(link)
117     ty = doc.getElementsByTagName("meta")[0].getAttribute("type")
118     print '[TODIC]'+str(ty)
119 torben 1646
120 torben 1678 if ty == 'clipList':
121 torben 1646 mode = '50'
122     folder = False
123     else:
124     mode = '1'
125     folder = True
126    
127 torben 1829
128 torben 1678 entries = doc.getElementsByTagName("entry")
129     l=len(entries)
130     description = ''
131     for entry in entries:
132     name = getText( entry.getElementsByTagName("title") )
133     url = getText( entry.getElementsByTagName("url") )
134     thumb = getText( entry.getElementsByTagName("cover") )
135     description = getText( entry.getElementsByTagName("description") )
136 torben 1830 playcount = getText( entry.getElementsByTagName("playcount") )
137 torben 1647
138 torben 1830 if playcount == '':
139     playcount = '0'
140     playcount = int(playcount)
141    
142 torben 1678 name = name.encode('latin-1')
143     description = description.encode('latin-1')
144    
145     ## print "name:" + name
146     # print "url:" + url
147     # print "thumb:" + thumb
148     # print "description:" + description
149    
150    
151 torben 1647 listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
152 torben 1648 listitem.setProperty('Fanart_Image', fanartImage)
153 torben 1650 if mode == '50':
154     infoLabels = {}
155     infoLabels['title'] = name
156 torben 1829 infoLabels['plot'] = description
157     infoLabels['playcount'] = playcount
158 torben 1650 listitem.setInfo('video', infoLabels)
159 torben 1648
160 torben 1678 u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url)
161 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
162 torben 1629
163 torben 1659 if (endlist == True):
164     xbmcplugin.endOfDirectory(int(sys.argv[1]))
165 torben 1629
166    
167    
168 torben 1659
169 torben 1629 def play_video(url, name):
170 torben 1678 xml = open_url(url)
171 torben 1914 print 'TODIC url: ' + str(url)
172     print 'TODIC xml: '+ xml
173 torben 1678
174     doc = parseString(xml)
175     url = getText( doc.getElementsByTagName("url") )
176    
177 torben 1914 subtitleurl = getText( doc.getElementsByTagName("subtitles") )
178     subtitlesfile = os.path.join(datapath,'temp.srt')
179    
180     print '[TODIC] subs: '+str(subtitleurl)
181     if len(subtitleurl) > 0:
182     subtitles = open_url(subtitleurl)
183     SaveFile(subtitlesfile, subtitles)
184     print 'TODIC downloaded subtitles'
185    
186    
187    
188 torben 1629 image = xbmc.getInfoImage( 'ListItem.Thumb' )
189     listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image)
190     listitem.setInfo( type = "Video", infoLabels={ "Title": name } )
191    
192 torben 1676 player = TodicPlayer(xbmc.PLAYER_CORE_AUTO)
193     player.play(str(url), listitem)
194 torben 1914
195     #kan ikke loade subtitles hvis foerend playeren koerer
196     count = 0
197     while not xbmc.Player().isPlaying():
198     xbmc.sleep(500)
199     count += 1
200     if count > 10:
201     break
202    
203    
204     if xbmc.Player().isPlaying():
205     if os.path.isfile(subtitlesfile):
206     player.setSubtitles(subtitlesfile)
207     print 'TODIC started subtitles'
208    
209 torben 1678 # player.callbackLoop()
210 torben 1676
211    
212    
213 torben 1631 def search():
214     search = getUserInput("Todic Søgning")
215 torben 1629
216 torben 1634 if (search != None and search != ""):
217     url = __backend__ + "&action=search&search=" + urllib.quote_plus(search)
218 torben 1631
219 torben 1634 #print "[TODIC] Search start: " + search
220     #print "[TODIC] Search url: " + url
221 torben 1631
222 torben 1646 buildList(url, "søgning")
223 torben 1631
224    
225    
226    
227    
228     #=================================== Tool Box =======================================
229     # shows a more userfriendly notification
230     def showMessage(heading, message):
231     duration = 15*1000
232     xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) )
233    
234    
235     # raise a keyboard for user input
236     def getUserInput(title = "Input", default="", hidden=False):
237     result = None
238    
239     # Fix for when this functions is called with default=None
240     if not default:
241     default = ""
242    
243     keyboard = xbmc.Keyboard(default, title)
244     keyboard.setHiddenInput(hidden)
245     keyboard.doModal()
246    
247     if keyboard.isConfirmed():
248     result = keyboard.getText()
249    
250     return result
251    
252    
253 torben 1629 def get_params():
254     param=[]
255     paramstring=sys.argv[2]
256     if len(paramstring)>=2:
257     params=sys.argv[2]
258     cleanedparams=params.replace('?','')
259     if (params[len(params)-1]=='/'):
260     params=params[0:len(params)-2]
261     pairsofparams=cleanedparams.split('&')
262     param={}
263     for i in range(len(pairsofparams)):
264     splitparams={}
265     splitparams=pairsofparams[i].split('=')
266     if (len(splitparams))==2:
267     param[splitparams[0]]=splitparams[1]
268     return param
269    
270    
271     params = get_params()
272     url = None
273     name = None
274     mode = None
275    
276     try:
277     url = urllib.unquote_plus(params["url"])
278     except:
279     pass
280     try:
281     name = urllib.unquote_plus(params["name"])
282     except:
283     pass
284     try:
285     mode = int(params["mode"])
286     except:
287     pass
288    
289 torben 1814 if url == 'refresh':
290     xbmc.output("[tvserver] Container.Refresh")
291     xbmc.executebuiltin("Container.Refresh")
292    
293 torben 1629
294 torben 1814 elif mode == None:
295 torben 1629 #build main menu
296     rootMenu()
297    
298     elif mode == 1:
299     #build list of movie starting letters
300     buildList(url, name)
301    
302 torben 1631 elif mode == 10:
303     search()
304    
305    
306 torben 1629 elif mode == 50:
307     play_video(url, name)

  ViewVC Help
Powered by ViewVC 1.1.20