/[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 1676 - (show annotations) (download) (as text)
Mon Jan 2 20:51:02 2012 UTC (12 years, 4 months ago) by torben
File MIME type: text/x-python
File size: 5625 byte(s)
experimental: base code for progress postback
1 '''
2 Todic plugin for XBMC
3 Version 0.0.2
4 '''
5
6 import sys
7 import cgi as urlparse
8 import os
9
10
11 import xbmc
12 import xbmcaddon
13 import xbmcgui
14 import xbmcplugin
15 import urllib
16 import urllib2, re
17
18 __addon__ = xbmcaddon.Addon(id='plugin.video.todic')
19 __key__ = __addon__.getSetting('xbmckey').lower()
20 __backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__
21 fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg')
22
23
24 class TodicPlayer(xbmc.Player):
25 def __init__(self, *args, **kwargs):
26 #xbmc.Player.__init__(selv,*args,**kwargs)
27 xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER )
28 self.stopped = False
29 self.started = False
30 print "[TodicPlayer] init"
31
32 # @catchall
33 def onPlayBackStarted(self):
34 self.started = True
35 print "[TodicPlayer] : started"
36 # super.onPlayBackStarted()
37
38 def onPlayBackStopped(self):
39 self.stopped = True
40 print "[TodicPlayer] : stopped"
41
42 def onPlayBackEnded(self):
43 self.stopped = True
44 print "[TodicPlayer] : ended"
45
46 def callbackLoop(self):
47 print "[Todic] startLoop"
48 while (self.stopped == False):
49 if (self.started == True ):
50 print "[todic] " + str(self.getTime())
51 xbmc.sleep(5000)
52
53
54
55
56 def open_url(url):
57 req = urllib2.Request(url)
58 content = urllib2.urlopen(req)
59 data = content.read()
60 content.close()
61 return data
62
63 def rootMenu():
64
65 buildList(__backend__, "", False) # call default list
66
67 # Adde xtra items to root menu
68 listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
69 listitem.setProperty('Fanart_Image', fanartImage)
70
71 u = sys.argv[0] + "?mode=10&name="
72 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True)
73
74 xbmcplugin.endOfDirectory(int(sys.argv[1]))
75
76
77 def buildList(url,title, endlist=True):
78 print '[TODIC]:'+str(url)
79 link = open_url(url)
80 ty=re.compile('<meta type=\'(.+?)\'').findall(link)
81 print '[TODIC]'+str(ty[0])
82
83 if ty[0] == 'clipList':
84 mode = '50'
85 folder = False
86 else:
87 mode = '1'
88 folder = True
89
90 m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover><description>(.*)</description>').findall(link)
91 l=len(m)
92 for name,url,thumb,description in m:
93
94 listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
95 listitem.setProperty('Fanart_Image', fanartImage)
96 if mode == '50':
97 infoLabels = {}
98 infoLabels['title'] = name
99 infoLabels['plot'] = description
100 listitem.setInfo('video', infoLabels)
101
102 u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)
103 ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
104
105 if (endlist == True):
106 xbmcplugin.endOfDirectory(int(sys.argv[1]))
107
108
109
110
111 def play_video(url, name):
112 link = open_url(url)
113 match=re.compile('<url>(.+?)</url>').findall(link)
114 url = match[0]
115 print '[TODIC]:'+str(url)
116 image = xbmc.getInfoImage( 'ListItem.Thumb' )
117 listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image)
118 # listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png')
119 listitem.setInfo( type = "Video", infoLabels={ "Title": name } )
120 # xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem)
121
122 player = TodicPlayer(xbmc.PLAYER_CORE_AUTO)
123 player.play(str(url), listitem)
124 player.callbackLoop()
125
126
127
128 def search():
129 search = getUserInput("Todic Søgning")
130
131 if (search != None and search != ""):
132 url = __backend__ + "&action=search&search=" + urllib.quote_plus(search)
133
134 #print "[TODIC] Search start: " + search
135 #print "[TODIC] Search url: " + url
136
137 buildList(url, "søgning")
138
139
140
141
142
143 #=================================== Tool Box =======================================
144 # shows a more userfriendly notification
145 def showMessage(heading, message):
146 duration = 15*1000
147 xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) )
148
149
150 # raise a keyboard for user input
151 def getUserInput(title = "Input", default="", hidden=False):
152 result = None
153
154 # Fix for when this functions is called with default=None
155 if not default:
156 default = ""
157
158 keyboard = xbmc.Keyboard(default, title)
159 keyboard.setHiddenInput(hidden)
160 keyboard.doModal()
161
162 if keyboard.isConfirmed():
163 result = keyboard.getText()
164
165 return result
166
167
168 def get_params():
169 param=[]
170 paramstring=sys.argv[2]
171 if len(paramstring)>=2:
172 params=sys.argv[2]
173 cleanedparams=params.replace('?','')
174 if (params[len(params)-1]=='/'):
175 params=params[0:len(params)-2]
176 pairsofparams=cleanedparams.split('&')
177 param={}
178 for i in range(len(pairsofparams)):
179 splitparams={}
180 splitparams=pairsofparams[i].split('=')
181 if (len(splitparams))==2:
182 param[splitparams[0]]=splitparams[1]
183 return param
184
185 params = get_params()
186 url = None
187 name = None
188 mode = None
189
190 params = get_params()
191 url = None
192 name = None
193 mode = None
194
195 try:
196 url = urllib.unquote_plus(params["url"])
197 except:
198 pass
199 try:
200 name = urllib.unquote_plus(params["name"])
201 except:
202 pass
203 try:
204 mode = int(params["mode"])
205 except:
206 pass
207
208
209 if mode == None:
210 #build main menu
211 rootMenu()
212
213 elif mode == 1:
214 #build list of movie starting letters
215 buildList(url, name)
216
217 elif mode == 10:
218 search()
219
220
221 elif mode == 50:
222 play_video(url, name)
223
224
225
226 # xbmcplugin.endOfDirectory(int(sys.argv[1]))

  ViewVC Help
Powered by ViewVC 1.1.20