/[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 2097 - (hide annotations) (download) (as text)
Sun Jan 5 22:00:42 2014 UTC (10 years, 4 months ago) by torben
File MIME type: text/x-python
File size: 8233 byte(s)
implementér serie søgning
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 1972 Version 0.0.9
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 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 2097 #add search series
110     listitem = xbmcgui.ListItem(label = "Søg Serier ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
111     listitem.setProperty('Fanart_Image', fanartImage)
112    
113     u = sys.argv[0] + "?mode=11&name="
114     ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)
115    
116 torben 1629 xbmcplugin.endOfDirectory(int(sys.argv[1]))
117    
118    
119 torben 1659 def buildList(url,title, endlist=True):
120 torben 1914 print '[TODIC]:'+str(url)
121 torben 1678
122 torben 1629 link = open_url(url)
123 torben 1678 doc = parseString(link)
124     ty = doc.getElementsByTagName("meta")[0].getAttribute("type")
125     print '[TODIC]'+str(ty)
126 torben 1646
127 torben 1678 if ty == 'clipList':
128 torben 1646 mode = '50'
129     folder = False
130     else:
131     mode = '1'
132     folder = True
133    
134 torben 1829
135 torben 1678 entries = doc.getElementsByTagName("entry")
136     l=len(entries)
137     description = ''
138     for entry in entries:
139     name = getText( entry.getElementsByTagName("title") )
140     url = getText( entry.getElementsByTagName("url") )
141     thumb = getText( entry.getElementsByTagName("cover") )
142     description = getText( entry.getElementsByTagName("description") )
143 torben 1830 playcount = getText( entry.getElementsByTagName("playcount") )
144 torben 1647
145 torben 1830 if playcount == '':
146     playcount = '0'
147     playcount = int(playcount)
148    
149 torben 1678
150     ## print "name:" + name
151     # print "url:" + url
152     # print "thumb:" + thumb
153     # print "description:" + description
154    
155    
156 torben 1647 listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
157 torben 1648 listitem.setProperty('Fanart_Image', fanartImage)
158 torben 1650 if mode == '50':
159     infoLabels = {}
160     infoLabels['title'] = name
161 torben 1829 infoLabels['plot'] = description
162     infoLabels['playcount'] = playcount
163 torben 1650 listitem.setInfo('video', infoLabels)
164 torben 1648
165 torben 1923 name = name.encode('UTF-8')
166     description = description.encode('UTF-8')
167    
168    
169 torben 1678 u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url)
170 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
171 torben 1629
172 torben 1659 if (endlist == True):
173     xbmcplugin.endOfDirectory(int(sys.argv[1]))
174 torben 1629
175    
176    
177 torben 1659
178 torben 1629 def play_video(url, name):
179 torben 1678 xml = open_url(url)
180 torben 1914 print 'TODIC url: ' + str(url)
181     print 'TODIC xml: '+ xml
182 torben 1678
183     doc = parseString(xml)
184     url = getText( doc.getElementsByTagName("url") )
185    
186 torben 1914 subtitleurl = getText( doc.getElementsByTagName("subtitles") )
187     subtitlesfile = os.path.join(datapath,'temp.srt')
188    
189 torben 1917 #if old srt file exists delete it first
190     if os.path.isfile(subtitlesfile):
191     os.unlink(subtitlesfile)
192    
193 torben 1914 print '[TODIC] subs: '+str(subtitleurl)
194     if len(subtitleurl) > 0:
195     subtitles = open_url(subtitleurl)
196     SaveFile(subtitlesfile, subtitles)
197     print 'TODIC downloaded subtitles'
198    
199    
200    
201 torben 1629 image = xbmc.getInfoImage( 'ListItem.Thumb' )
202     listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image)
203     listitem.setInfo( type = "Video", infoLabels={ "Title": name } )
204    
205 torben 1676 player = TodicPlayer(xbmc.PLAYER_CORE_AUTO)
206     player.play(str(url), listitem)
207 torben 1914
208     #kan ikke loade subtitles hvis foerend playeren koerer
209     count = 0
210     while not xbmc.Player().isPlaying():
211     xbmc.sleep(500)
212     count += 1
213     if count > 10:
214     break
215    
216    
217     if xbmc.Player().isPlaying():
218     if os.path.isfile(subtitlesfile):
219     player.setSubtitles(subtitlesfile)
220     print 'TODIC started subtitles'
221 torben 1917 else:
222     player.disableSubtitles()
223 torben 1914
224 torben 1678 # player.callbackLoop()
225 torben 1676
226    
227    
228 torben 1631 def search():
229     search = getUserInput("Todic Søgning")
230 torben 1629
231 torben 1634 if (search != None and search != ""):
232     url = __backend__ + "&action=search&search=" + urllib.quote_plus(search)
233 torben 1631
234 torben 1634 #print "[TODIC] Search start: " + search
235     #print "[TODIC] Search url: " + url
236 torben 1631
237 torben 1646 buildList(url, "søgning")
238 torben 1631
239 torben 2097 def searchSeries():
240     search = getUserInput("Todic Serie Søgning")
241    
242     if (search != None and search != ""):
243     url = __backend__ + "&action=searchseries&search=" + urllib.quote_plus(search)
244    
245     #print "[TODIC] Search start: " + search
246     #print "[TODIC] Search url: " + url
247    
248     buildList(url, "serie søgning")
249    
250 torben 1631
251    
252    
253    
254     #=================================== Tool Box =======================================
255     # shows a more userfriendly notification
256     def showMessage(heading, message):
257     duration = 15*1000
258     xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) )
259    
260    
261     # raise a keyboard for user input
262     def getUserInput(title = "Input", default="", hidden=False):
263     result = None
264    
265     # Fix for when this functions is called with default=None
266     if not default:
267     default = ""
268    
269     keyboard = xbmc.Keyboard(default, title)
270     keyboard.setHiddenInput(hidden)
271     keyboard.doModal()
272    
273     if keyboard.isConfirmed():
274     result = keyboard.getText()
275    
276     return result
277    
278    
279 torben 1629 def get_params():
280     param=[]
281     paramstring=sys.argv[2]
282     if len(paramstring)>=2:
283     params=sys.argv[2]
284     cleanedparams=params.replace('?','')
285     if (params[len(params)-1]=='/'):
286     params=params[0:len(params)-2]
287     pairsofparams=cleanedparams.split('&')
288     param={}
289     for i in range(len(pairsofparams)):
290     splitparams={}
291     splitparams=pairsofparams[i].split('=')
292     if (len(splitparams))==2:
293     param[splitparams[0]]=splitparams[1]
294     return param
295    
296    
297     params = get_params()
298     url = None
299     name = None
300     mode = None
301    
302     try:
303     url = urllib.unquote_plus(params["url"])
304     except:
305     pass
306     try:
307     name = urllib.unquote_plus(params["name"])
308     except:
309     pass
310     try:
311     mode = int(params["mode"])
312     except:
313     pass
314    
315 torben 1814 if url == 'refresh':
316 torben 1972 #xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12
317 torben 1814 xbmc.executebuiltin("Container.Refresh")
318    
319 torben 1629
320 torben 1814 elif mode == None:
321 torben 1629 #build main menu
322     rootMenu()
323    
324     elif mode == 1:
325     #build list of movie starting letters
326     buildList(url, name)
327    
328 torben 1631 elif mode == 10:
329     search()
330 torben 2097
331     elif mode == 11:
332     searchSeries()
333 torben 1631
334    
335 torben 1629 elif mode == 50:
336     play_video(url, name)

  ViewVC Help
Powered by ViewVC 1.1.20