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

  ViewVC Help
Powered by ViewVC 1.1.20