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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1972 - (show annotations) (download) (as text)
Thu Apr 18 16:18:22 2013 UTC (11 years, 1 month ago) by torben
File MIME type: text/x-python
File size: 7548 byte(s)
få refresh list til at virke igen (10 nye tilfældige)
1
2 # This Python file uses the following encoding: utf-8
3
4 '''
5 Todic plugin for XBMC
6 Version 0.0.9
7 '''
8
9 import sys
10 import cgi as urlparse
11 import os
12
13
14 import xbmc
15 import xbmcaddon
16 import xbmcgui
17 import xbmcplugin
18 import urllib
19 import urllib2
20
21 from xml.dom.minidom import parseString
22
23 __addon__ = xbmcaddon.Addon(id='plugin.video.todic')
24 __key__ = __addon__.getSetting('xbmckey').lower()
25 __backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__
26 fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg')
27 datapath = xbmc.translatePath('special://profile/addon_data/plugin.video.todic/')
28
29
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 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
69 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
78 def SaveFile(path, data):
79 file = open(path,'w')
80 file.write(data)
81 file.close()
82
83
84 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
93 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 buildList(__backend__, "", False) # call default list
101
102 # Adde xtra items to root menu
103 listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
104 listitem.setProperty('Fanart_Image', fanartImage)
105
106 u = sys.argv[0] + "?mode=10&name="
107 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)
108
109 xbmcplugin.endOfDirectory(int(sys.argv[1]))
110
111
112 def buildList(url,title, endlist=True):
113 print '[TODIC]:'+str(url)
114
115 link = open_url(url)
116 doc = parseString(link)
117 ty = doc.getElementsByTagName("meta")[0].getAttribute("type")
118 print '[TODIC]'+str(ty)
119
120 if ty == 'clipList':
121 mode = '50'
122 folder = False
123 else:
124 mode = '1'
125 folder = True
126
127
128 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 playcount = getText( entry.getElementsByTagName("playcount") )
137
138 if playcount == '':
139 playcount = '0'
140 playcount = int(playcount)
141
142
143 ## print "name:" + name
144 # print "url:" + url
145 # print "thumb:" + thumb
146 # print "description:" + description
147
148
149 listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
150 listitem.setProperty('Fanart_Image', fanartImage)
151 if mode == '50':
152 infoLabels = {}
153 infoLabels['title'] = name
154 infoLabels['plot'] = description
155 infoLabels['playcount'] = playcount
156 listitem.setInfo('video', infoLabels)
157
158 name = name.encode('UTF-8')
159 description = description.encode('UTF-8')
160
161
162 u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url)
163 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
164
165 if (endlist == True):
166 xbmcplugin.endOfDirectory(int(sys.argv[1]))
167
168
169
170
171 def play_video(url, name):
172 xml = open_url(url)
173 print 'TODIC url: ' + str(url)
174 print 'TODIC xml: '+ xml
175
176 doc = parseString(xml)
177 url = getText( doc.getElementsByTagName("url") )
178
179 subtitleurl = getText( doc.getElementsByTagName("subtitles") )
180 subtitlesfile = os.path.join(datapath,'temp.srt')
181
182 #if old srt file exists delete it first
183 if os.path.isfile(subtitlesfile):
184 os.unlink(subtitlesfile)
185
186 print '[TODIC] subs: '+str(subtitleurl)
187 if len(subtitleurl) > 0:
188 subtitles = open_url(subtitleurl)
189 SaveFile(subtitlesfile, subtitles)
190 print 'TODIC downloaded subtitles'
191
192
193
194 image = xbmc.getInfoImage( 'ListItem.Thumb' )
195 listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image)
196 listitem.setInfo( type = "Video", infoLabels={ "Title": name } )
197
198 player = TodicPlayer(xbmc.PLAYER_CORE_AUTO)
199 player.play(str(url), listitem)
200
201 #kan ikke loade subtitles hvis foerend playeren koerer
202 count = 0
203 while not xbmc.Player().isPlaying():
204 xbmc.sleep(500)
205 count += 1
206 if count > 10:
207 break
208
209
210 if xbmc.Player().isPlaying():
211 if os.path.isfile(subtitlesfile):
212 player.setSubtitles(subtitlesfile)
213 print 'TODIC started subtitles'
214 else:
215 player.disableSubtitles()
216
217 # player.callbackLoop()
218
219
220
221 def search():
222 search = getUserInput("Todic Søgning")
223
224 if (search != None and search != ""):
225 url = __backend__ + "&action=search&search=" + urllib.quote_plus(search)
226
227 #print "[TODIC] Search start: " + search
228 #print "[TODIC] Search url: " + url
229
230 buildList(url, "søgning")
231
232
233
234
235
236 #=================================== Tool Box =======================================
237 # shows a more userfriendly notification
238 def showMessage(heading, message):
239 duration = 15*1000
240 xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) )
241
242
243 # raise a keyboard for user input
244 def getUserInput(title = "Input", default="", hidden=False):
245 result = None
246
247 # Fix for when this functions is called with default=None
248 if not default:
249 default = ""
250
251 keyboard = xbmc.Keyboard(default, title)
252 keyboard.setHiddenInput(hidden)
253 keyboard.doModal()
254
255 if keyboard.isConfirmed():
256 result = keyboard.getText()
257
258 return result
259
260
261 def get_params():
262 param=[]
263 paramstring=sys.argv[2]
264 if len(paramstring)>=2:
265 params=sys.argv[2]
266 cleanedparams=params.replace('?','')
267 if (params[len(params)-1]=='/'):
268 params=params[0:len(params)-2]
269 pairsofparams=cleanedparams.split('&')
270 param={}
271 for i in range(len(pairsofparams)):
272 splitparams={}
273 splitparams=pairsofparams[i].split('=')
274 if (len(splitparams))==2:
275 param[splitparams[0]]=splitparams[1]
276 return param
277
278
279 params = get_params()
280 url = None
281 name = None
282 mode = None
283
284 try:
285 url = urllib.unquote_plus(params["url"])
286 except:
287 pass
288 try:
289 name = urllib.unquote_plus(params["name"])
290 except:
291 pass
292 try:
293 mode = int(params["mode"])
294 except:
295 pass
296
297 if url == 'refresh':
298 #xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12
299 xbmc.executebuiltin("Container.Refresh")
300
301
302 elif mode == None:
303 #build main menu
304 rootMenu()
305
306 elif mode == 1:
307 #build list of movie starting letters
308 buildList(url, name)
309
310 elif mode == 10:
311 search()
312
313
314 elif mode == 50:
315 play_video(url, name)

  ViewVC Help
Powered by ViewVC 1.1.20