/[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 1830 - (hide annotations) (download) (as text)
Sun Aug 19 20:41:20 2012 UTC (11 years, 9 months ago) by torben
File MIME type: text/x-python
File size: 6567 byte(s)
take 2 on playcount
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 1829
122 torben 1678 entries = doc.getElementsByTagName("entry")
123     l=len(entries)
124     description = ''
125     for entry in entries:
126     name = getText( entry.getElementsByTagName("title") )
127     url = getText( entry.getElementsByTagName("url") )
128     thumb = getText( entry.getElementsByTagName("cover") )
129     description = getText( entry.getElementsByTagName("description") )
130 torben 1830 playcount = getText( entry.getElementsByTagName("playcount") )
131 torben 1647
132 torben 1830 if playcount == '':
133     playcount = '0'
134     playcount = int(playcount)
135    
136 torben 1678 name = name.encode('latin-1')
137     description = description.encode('latin-1')
138    
139     ## print "name:" + name
140     # print "url:" + url
141     # print "thumb:" + thumb
142     # print "description:" + description
143    
144    
145 torben 1647 listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
146 torben 1648 listitem.setProperty('Fanart_Image', fanartImage)
147 torben 1650 if mode == '50':
148     infoLabels = {}
149     infoLabels['title'] = name
150 torben 1829 infoLabels['plot'] = description
151     infoLabels['playcount'] = playcount
152 torben 1650 listitem.setInfo('video', infoLabels)
153 torben 1648
154 torben 1678 u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url)
155 torben 1630 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
156 torben 1629
157 torben 1659 if (endlist == True):
158     xbmcplugin.endOfDirectory(int(sys.argv[1]))
159 torben 1629
160    
161    
162 torben 1659
163 torben 1629 def play_video(url, name):
164 torben 1678 xml = open_url(url)
165    
166     doc = parseString(xml)
167     url = getText( doc.getElementsByTagName("url") )
168    
169 torben 1629 print '[TODIC]:'+str(url)
170     image = xbmc.getInfoImage( 'ListItem.Thumb' )
171     listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image)
172     listitem.setInfo( type = "Video", infoLabels={ "Title": name } )
173    
174 torben 1676 player = TodicPlayer(xbmc.PLAYER_CORE_AUTO)
175     player.play(str(url), listitem)
176 torben 1678 # player.callbackLoop()
177 torben 1676
178    
179    
180 torben 1631 def search():
181     search = getUserInput("Todic Søgning")
182 torben 1629
183 torben 1634 if (search != None and search != ""):
184     url = __backend__ + "&action=search&search=" + urllib.quote_plus(search)
185 torben 1631
186 torben 1634 #print "[TODIC] Search start: " + search
187     #print "[TODIC] Search url: " + url
188 torben 1631
189 torben 1646 buildList(url, "søgning")
190 torben 1631
191    
192    
193    
194    
195     #=================================== Tool Box =======================================
196     # shows a more userfriendly notification
197     def showMessage(heading, message):
198     duration = 15*1000
199     xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) )
200    
201    
202     # raise a keyboard for user input
203     def getUserInput(title = "Input", default="", hidden=False):
204     result = None
205    
206     # Fix for when this functions is called with default=None
207     if not default:
208     default = ""
209    
210     keyboard = xbmc.Keyboard(default, title)
211     keyboard.setHiddenInput(hidden)
212     keyboard.doModal()
213    
214     if keyboard.isConfirmed():
215     result = keyboard.getText()
216    
217     return result
218    
219    
220 torben 1629 def get_params():
221     param=[]
222     paramstring=sys.argv[2]
223     if len(paramstring)>=2:
224     params=sys.argv[2]
225     cleanedparams=params.replace('?','')
226     if (params[len(params)-1]=='/'):
227     params=params[0:len(params)-2]
228     pairsofparams=cleanedparams.split('&')
229     param={}
230     for i in range(len(pairsofparams)):
231     splitparams={}
232     splitparams=pairsofparams[i].split('=')
233     if (len(splitparams))==2:
234     param[splitparams[0]]=splitparams[1]
235     return param
236    
237    
238     params = get_params()
239     url = None
240     name = None
241     mode = None
242    
243     try:
244     url = urllib.unquote_plus(params["url"])
245     except:
246     pass
247     try:
248     name = urllib.unquote_plus(params["name"])
249     except:
250     pass
251     try:
252     mode = int(params["mode"])
253     except:
254     pass
255    
256 torben 1814 if url == 'refresh':
257     xbmc.output("[tvserver] Container.Refresh")
258     xbmc.executebuiltin("Container.Refresh")
259    
260 torben 1629
261 torben 1814 elif mode == None:
262 torben 1629 #build main menu
263     rootMenu()
264    
265     elif mode == 1:
266     #build list of movie starting letters
267     buildList(url, name)
268    
269 torben 1631 elif mode == 10:
270     search()
271    
272    
273 torben 1629 elif mode == 50:
274     play_video(url, name)

  ViewVC Help
Powered by ViewVC 1.1.20