3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 0.0.9 |
Version 0.1.2 |
7 |
''' |
''' |
8 |
|
|
9 |
import sys |
import sys |
|
import cgi as urlparse |
|
10 |
import os |
import os |
11 |
|
|
12 |
|
|
17 |
import urllib |
import urllib |
18 |
import urllib2 |
import urllib2 |
19 |
|
|
20 |
|
# import pprint |
21 |
|
|
22 |
from xml.dom.minidom import parseString |
from xml.dom.minidom import parseString |
23 |
|
from time import time |
24 |
|
|
25 |
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
__addon__ = xbmcaddon.Addon(id='plugin.video.todic') |
26 |
__key__ = __addon__.getSetting('xbmckey').lower() |
__key__ = __addon__.getSetting('xbmckey').lower() |
27 |
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
__backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__ |
28 |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg') |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
29 |
datapath = xbmc.translatePath('special://profile/addon_data/plugin.video.todic/') |
datapath = xbmc.translatePath( |
30 |
|
'special://profile/addon_data/plugin.video.todic/') |
31 |
|
|
32 |
class TodicPlayer(xbmc.Player): |
ADDON_PATH = __addon__.getAddonInfo('path') |
33 |
def __init__(self, *args, **kwargs): |
SkinMasterPath = os.path.join(ADDON_PATH, 'skins') + '/' |
34 |
#xbmc.Player.__init__(selv,*args,**kwargs) |
MySkinPath = (os.path.join(SkinMasterPath, '720p')) + '/' |
35 |
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER ) |
MySkin = 'main.xml' |
36 |
self.stopped = False |
|
37 |
self.started = False |
|
38 |
print "[TodicPlayer] init" |
class TodicMovieDialog(xbmcgui.WindowXMLDialog): |
39 |
|
|
40 |
# @catchall |
def __new__(cls): |
41 |
def onPlayBackStarted(self): |
return super(TodicMovieDialog, cls).__new__(cls, "main.xml", ADDON_PATH) |
42 |
self.started = True |
|
43 |
print "[TodicPlayer] : started" |
def __init__(self): |
44 |
# super.onPlayBackStarted() |
super(TodicMovieDialog, self).__init__() |
45 |
|
self.position = 0 |
46 |
def onPlayBackStopped(self): |
|
47 |
self.stopped = True |
def onClick(self, controlId): |
48 |
print "[TodicPlayer] : stopped" |
print "[Todic] MovieDialog OnClick: " + str(controlId) |
49 |
|
|
50 |
def onPlayBackEnded(self): |
if (controlId == 50): |
51 |
self.stopped = True |
self.close() |
52 |
print "[TodicPlayer] : ended" |
play_real_video(self.url, self.name, 0) |
53 |
|
|
54 |
def callbackLoop(self): |
if (controlId == 51): |
55 |
print "[Todic] startLoop" |
self.close() |
56 |
while (self.stopped == False): |
play_real_video(self.url, self.name, self.position) |
57 |
if (self.started == True ): |
|
58 |
print "[todic] " + str(self.getTime()) |
if (controlId == 98): |
59 |
xbmc.sleep(5000) |
self.close() |
60 |
|
|
61 |
|
def onInit(self): |
62 |
def getText2(nodelist): |
|
63 |
rc = [] |
print "[Todic] MovieDialog onInit" |
64 |
for node in nodelist: |
self.getControl(1).setLabel(self.name) |
65 |
if node.nodeType == node.TEXT_NODE: |
self.getControl(2).setLabel(self.moviegroups) |
66 |
rc.append(node.data) |
self.getControl(3).setLabel(self.description) |
67 |
else: |
self.getControl(10).setLabel(self.playlength) |
68 |
rc.append( getText(node.childNodes) ) |
self.getControl(11).setLabel(self.codecdetails) |
69 |
return ''.join(rc) |
|
70 |
|
if (self.position > 0): |
71 |
def getText(nodelist): |
self.getControl(51).setVisible(True) |
72 |
if nodelist.length == 0: |
self.getControl(50).setPosition(100, 570) |
73 |
return '' |
self.getControl(51).setPosition(450, 570) |
74 |
else: |
self.getControl(50).controlLeft( self.getControl(51) ) |
75 |
if nodelist[0].childNodes.length == 0: |
self.getControl(50).controlRight( self.getControl(51) ) |
76 |
return '' |
else: |
77 |
else: |
self.getControl(51).setVisible(False) |
|
return nodelist[0].childNodes[0].nodeValue |
|
|
|
|
|
def SaveFile(path, data): |
|
|
file = open(path,'w') |
|
|
file.write(data) |
|
|
file.close() |
|
|
|
|
|
|
|
|
def open_url(url): |
|
|
req = urllib2.Request(url) |
|
|
content = urllib2.urlopen(req) |
|
|
data = content.read() |
|
|
content.close() |
|
|
return data |
|
|
|
|
|
def rootMenu(): |
|
|
|
|
|
msg = open_url(__backend__ + "&action=messages") |
|
|
msg = msg.strip() |
|
|
|
|
|
if msg != "": |
|
|
dialog = xbmcgui.Dialog() |
|
|
dialog.ok('XBMC Todic', msg) |
|
78 |
|
|
79 |
buildList(__backend__, "", False) # call default list |
#orig_img_width = self.getControl(40).getWidth() |
80 |
|
#self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width |
81 |
|
#self.getControl(40).setWidth(int(self.starwidth)) |
82 |
|
|
83 |
|
def setDetailsDoc(self, detailsDoc): |
84 |
|
print "[Todic] MovieDialog setDetailsDoc:" |
85 |
|
self.imdbrating = getText(detailsDoc.getElementsByTagName("imdbrating")) |
86 |
|
self.moviegroups = getText(detailsDoc.getElementsByTagName("moviegroups")) |
87 |
|
self.playlength = getText(detailsDoc.getElementsByTagName("playlength")) |
88 |
|
self.codecdetails = getText(detailsDoc.getElementsByTagName("codecdetails")) |
89 |
|
self.position = int( getText(detailsDoc.getElementsByTagName("position")) ) |
90 |
|
|
91 |
# Adde xtra items to root menu |
def setUrl(self, url): |
92 |
listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
self.url = url |
|
listitem.setProperty('Fanart_Image', fanartImage) |
|
93 |
|
|
94 |
u = sys.argv[0] + "?mode=10&name=" |
def setName(self, name): |
95 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
self.name = name |
96 |
|
|
97 |
#add search series |
def setDescription(self, description): |
98 |
listitem = xbmcgui.ListItem(label = "Søg Serier ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
self.description = description |
|
listitem.setProperty('Fanart_Image', fanartImage) |
|
99 |
|
|
|
u = sys.argv[0] + "?mode=11&name=" |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
|
100 |
|
|
101 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
class TodicPlayer(xbmc.Player): |
102 |
|
|
103 |
|
def __init__(self, *args, **kwargs): |
104 |
|
# xbmc.Player.__init__(selv,*args,**kwargs) |
105 |
|
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) |
106 |
|
self.stopped = False |
107 |
|
self.started = False |
108 |
|
self.playingPosition = 0.0 |
109 |
|
self.lastReport = 0 |
110 |
|
print "[TodicPlayer] init" |
111 |
|
|
112 |
|
def onPlayBackStarted(self): |
113 |
|
self.started = True |
114 |
|
print "[TodicPlayer] : started" |
115 |
|
|
116 |
|
#When user presses stop, we report back the the position registered in the last call to self.tick() |
117 |
|
def onPlayBackStopped(self): |
118 |
|
self.stopped = True |
119 |
|
print "[TodicPlayer] : stopped" |
120 |
|
self.reportPlaytime("stopped") |
121 |
|
|
122 |
|
def onPlayBackPaused(self): |
123 |
|
print "[TodicPlayer] : paused" |
124 |
|
self.reportPlaytime("paused") |
125 |
|
|
126 |
|
def onPlayBackResumed(self): |
127 |
|
print "[TodicPlayer] : resumed" |
128 |
|
self.reportPlaytime("resumed") |
129 |
|
|
130 |
|
|
131 |
|
def onPlayBackEnded(self): |
132 |
|
self.stopped = True |
133 |
|
print "[TodicPlayer] : ended" |
134 |
|
self.reportPlaytime("ended") |
135 |
|
|
136 |
|
def tick(self): |
137 |
|
#print "[Todic] Tick: " + str( self.isPlaying() ) |
138 |
|
if ( self.isPlaying() ): |
139 |
|
self.playingPosition = self.getTime() |
140 |
|
now = time() |
141 |
|
#print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) |
142 |
|
if ( (now - self.lastReport) > 60.0): |
143 |
|
self.lastReport = now |
144 |
|
self.reportPlaytime("playing") |
145 |
|
|
146 |
|
def reportPlaytime(self, subaction): |
147 |
|
if (self.playingPosition > 60): |
148 |
|
url = __backend__ + "&action=playbacktime&subaction=" + subaction + "&time=" + str( self.playingPosition ) |
149 |
|
print "[Todic] reportPlaytime:" + url |
150 |
|
open_url_safe(url) |
151 |
|
|
|
def buildList(url,title, endlist=True): |
|
|
print '[TODIC]:'+str(url) |
|
152 |
|
|
|
link = open_url(url) |
|
|
doc = parseString(link) |
|
|
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
|
|
print '[TODIC]'+str(ty) |
|
153 |
|
|
154 |
if ty == 'clipList': |
def getText2(nodelist): |
155 |
mode = '50' |
rc = [] |
156 |
folder = False |
for node in nodelist: |
157 |
|
if node.nodeType == node.TEXT_NODE: |
158 |
|
rc.append(node.data) |
159 |
else: |
else: |
160 |
mode = '1' |
rc.append(getText(node.childNodes)) |
161 |
folder = True |
return ''.join(rc) |
162 |
|
|
163 |
|
|
164 |
entries = doc.getElementsByTagName("entry") |
def getText(nodelist): |
165 |
l=len(entries) |
if nodelist.length == 0: |
166 |
description = '' |
return '' |
167 |
for entry in entries: |
else: |
168 |
name = getText( entry.getElementsByTagName("title") ) |
if nodelist[0].childNodes.length == 0: |
169 |
url = getText( entry.getElementsByTagName("url") ) |
return '' |
170 |
thumb = getText( entry.getElementsByTagName("cover") ) |
else: |
171 |
description = getText( entry.getElementsByTagName("description") ) |
return nodelist[0].childNodes[0].nodeValue |
|
playcount = getText( entry.getElementsByTagName("playcount") ) |
|
|
|
|
|
if playcount == '': |
|
|
playcount = '0' |
|
|
playcount = int(playcount) |
|
|
|
|
|
|
|
|
## print "name:" + name |
|
|
# print "url:" + url |
|
|
# print "thumb:" + thumb |
|
|
# print "description:" + description |
|
|
|
|
|
|
|
|
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
|
|
listitem.setProperty('Fanart_Image', fanartImage) |
|
|
if mode == '50': |
|
|
infoLabels = {} |
|
|
infoLabels['title'] = name |
|
|
infoLabels['plot'] = description |
|
|
infoLabels['playcount'] = playcount |
|
|
listitem.setInfo('video', infoLabels) |
|
|
|
|
|
name = name.encode('UTF-8') |
|
|
description = description.encode('UTF-8') |
|
172 |
|
|
173 |
|
|
|
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
|
174 |
|
|
175 |
if (endlist == True): |
def SaveFile(path, data): |
176 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
file = open(path, 'w') |
177 |
|
file.write(data) |
178 |
|
file.close() |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
def open_url(url): |
183 |
|
req = urllib2.Request(url) |
184 |
|
content = urllib2.urlopen(req) |
185 |
|
data = content.read() |
186 |
|
content.close() |
187 |
|
return data |
188 |
|
|
|
def play_video(url, name): |
|
|
xml = open_url(url) |
|
|
print 'TODIC url: ' + str(url) |
|
|
print 'TODIC xml: '+ xml |
|
189 |
|
|
190 |
doc = parseString(xml) |
# wraps open url in a catch-all exception handler |
191 |
url = getText( doc.getElementsByTagName("url") ) |
# usefull for periodic back-reporting that should not interrupt the program flow |
192 |
|
def open_url_safe(url): |
193 |
|
try: |
194 |
|
return open_url(url) |
195 |
|
except: |
196 |
|
print "[Todic] Some error during open_url call to ", url |
197 |
|
|
|
subtitleurl = getText( doc.getElementsByTagName("subtitles") ) |
|
|
subtitlesfile = os.path.join(datapath,'temp.srt') |
|
198 |
|
|
|
#if old srt file exists delete it first |
|
|
if os.path.isfile(subtitlesfile): |
|
|
os.unlink(subtitlesfile) |
|
199 |
|
|
200 |
print '[TODIC] subs: '+str(subtitleurl) |
def rootMenu(): |
|
if len(subtitleurl) > 0: |
|
|
subtitles = open_url(subtitleurl) |
|
|
SaveFile(subtitlesfile, subtitles) |
|
|
print 'TODIC downloaded subtitles' |
|
201 |
|
|
202 |
|
msg = open_url(__backend__ + "&action=messages") |
203 |
|
msg = msg.strip() |
204 |
|
|
205 |
|
if msg != "": |
206 |
|
dialog = xbmcgui.Dialog() |
207 |
|
dialog.ok('XBMC Todic', msg) |
208 |
|
|
209 |
|
buildList(__backend__, "", False) # call default list |
210 |
|
|
211 |
|
# Adde xtra items to root menu |
212 |
|
listitem = xbmcgui.ListItem( |
213 |
|
label="Søg Film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
214 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
215 |
|
|
216 |
|
u = sys.argv[0] + "?mode=10&name=" |
217 |
|
xbmcplugin.addDirectoryItem( |
218 |
|
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
219 |
|
|
220 |
|
# add search series |
221 |
|
listitem = xbmcgui.ListItem( |
222 |
|
label="Søg Serier ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
223 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
224 |
|
|
225 |
|
u = sys.argv[0] + "?mode=11&name=" |
226 |
|
xbmcplugin.addDirectoryItem( |
227 |
|
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
228 |
|
|
229 |
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
230 |
|
|
231 |
|
|
232 |
|
def buildList(url, title, endlist=True): |
233 |
|
print '[Todic]:' + str(url) |
234 |
|
|
235 |
|
link = open_url(url) |
236 |
|
doc = parseString(link) |
237 |
|
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
238 |
|
print '[Todic]' + str(ty) |
239 |
|
|
240 |
|
if ty == 'clipList': |
241 |
|
mode = '50' |
242 |
|
folder = False |
243 |
|
else: |
244 |
|
mode = '1' |
245 |
|
folder = True |
246 |
|
|
247 |
|
entries = doc.getElementsByTagName("entry") |
248 |
|
l = len(entries) |
249 |
|
description = '' |
250 |
|
for entry in entries: |
251 |
|
name = getText(entry.getElementsByTagName("title")) |
252 |
|
url = getText(entry.getElementsByTagName("url")) |
253 |
|
thumb = getText(entry.getElementsByTagName("cover")) |
254 |
|
description = getText(entry.getElementsByTagName("description")) |
255 |
|
playcount = getText(entry.getElementsByTagName("playcount")) |
256 |
|
|
257 |
|
|
258 |
|
if playcount == '': |
259 |
|
playcount = '0' |
260 |
|
playcount = int(playcount) |
261 |
|
|
262 |
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
# print "name:" + name |
263 |
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
# print "url:" + url |
264 |
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
# print "thumb:" + thumb |
265 |
|
# print "description:" + description |
266 |
|
listitem = xbmcgui.ListItem( |
267 |
|
label=name, label2='test', iconImage='DefaultFolder.png', thumbnailImage=thumb) |
268 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
269 |
|
if mode == '50': |
270 |
|
infoLabels = {} |
271 |
|
infoLabels['title'] = name |
272 |
|
infoLabels['plot'] = description |
273 |
|
infoLabels['playcount'] = playcount |
274 |
|
listitem.setInfo('video', infoLabels) |
275 |
|
|
276 |
|
name = name.encode('UTF-8') |
277 |
|
description = description.encode('UTF-8') |
278 |
|
|
279 |
|
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
280 |
|
name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) |
281 |
|
xbmcplugin.addDirectoryItem( |
282 |
|
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=folder, totalItems=l) |
283 |
|
|
284 |
|
if (endlist == True): |
285 |
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
286 |
|
|
287 |
|
|
288 |
|
def play_video(url, name, description): |
289 |
|
param1 = parse_parameter_string(url) |
290 |
|
clipkey = param1["clipkey"] |
291 |
|
|
292 |
|
print "[Todic] ClipKey:" + clipkey |
293 |
|
detailurl = __backend__ + "&action=clipdetails&clipkey=" + clipkey |
294 |
|
print "[Todic] detailURL = " + detailurl |
295 |
|
|
296 |
|
xml = open_url(detailurl) |
297 |
|
|
298 |
|
clipDetailsDoc = parseString(xml) |
299 |
|
savedPosition = int( getText(clipDetailsDoc.getElementsByTagName("position")) ) |
300 |
|
playPosition = 0 |
301 |
|
|
302 |
|
if (description == None or description == ""): |
303 |
|
if (savedPosition > 0): |
304 |
|
dialog = xbmcgui.Dialog() |
305 |
|
#yes / true -afspil fra position |
306 |
|
answer = dialog.yesno(heading='Todic', line1='Afspil fra sidste position', nolabel='Fra start', yeslabel='Fortsæt') |
307 |
|
if (answer == True): |
308 |
|
playPosition = savedPosition |
309 |
|
|
310 |
|
play_real_video(url, name, playPosition) |
311 |
|
|
312 |
|
else: |
313 |
|
d = TodicMovieDialog() |
314 |
|
d.setDetailsDoc(clipDetailsDoc) |
315 |
|
d.setName(name) |
316 |
|
d.setUrl(url) |
317 |
|
d.setDescription(description) |
318 |
|
|
319 |
|
d.doModal() |
320 |
|
|
321 |
|
|
322 |
|
def play_real_video(url, name, position): |
323 |
|
xml = open_url(url) |
324 |
|
print '[Todic] url: ' + str(url) |
325 |
|
print '[Todic] xml: ' + xml |
326 |
|
print '[Todic] pos: ' + str(position) |
327 |
|
|
328 |
|
doc = parseString(xml) |
329 |
|
url = getText(doc.getElementsByTagName("url")) |
330 |
|
|
331 |
|
subtitleurl = getText(doc.getElementsByTagName("subtitles")) |
332 |
|
subtitlesfile = os.path.join(datapath, 'temp.srt') |
333 |
|
|
334 |
|
# if old srt file exists delete it first |
335 |
|
if os.path.isfile(subtitlesfile): |
336 |
|
os.unlink(subtitlesfile) |
337 |
|
|
338 |
|
print '[Todic] subs: ' + str(subtitleurl) |
339 |
|
if len(subtitleurl) > 0: |
340 |
|
subtitles = open_url(subtitleurl) |
341 |
|
SaveFile(subtitlesfile, subtitles) |
342 |
|
print '[Todic] downloaded subtitles' |
343 |
|
|
344 |
|
image = xbmc.getInfoImage('ListItem.Thumb') |
345 |
|
listitem = xbmcgui.ListItem( |
346 |
|
label=name, iconImage='DefaultVideo.png', thumbnailImage=image) |
347 |
|
listitem.setInfo(type="Video", infoLabels={"Title": name}) |
348 |
|
listitem.setProperty('ResumeTime', '300') |
349 |
|
listitem.setProperty('TotalTime', '3000') |
350 |
|
|
351 |
|
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
352 |
|
player.play(str(url), listitem) |
353 |
|
|
354 |
|
# kan ikke loade subtitles hvis foerend playeren koerer |
355 |
|
count = 0 |
356 |
|
while not xbmc.Player().isPlaying(): |
357 |
|
xbmc.sleep(250) |
358 |
|
count += 1 |
359 |
|
if count > 10: |
360 |
|
break |
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
if xbmc.Player().isPlaying(): |
365 |
|
if os.path.isfile(subtitlesfile): |
366 |
|
player.setSubtitles(subtitlesfile) |
367 |
|
print '[Todic] started subtitles' |
368 |
|
else: |
369 |
|
player.disableSubtitles() |
370 |
|
|
|
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
|
|
player.play(str(url), listitem) |
|
371 |
|
|
372 |
#kan ikke loade subtitles hvis foerend playeren koerer |
if (position > 0): |
373 |
count = 0 |
while (player.getTotalTime() == 0.0): #Vent indtil vi har beregnet hvor langt klippet er |
374 |
while not xbmc.Player().isPlaying(): |
xbmc.sleep(250) |
|
xbmc.sleep(500) |
|
|
count += 1 |
|
|
if count > 10: |
|
|
break |
|
375 |
|
|
376 |
|
print "[Todic] totalTime " + str( player.getTotalTime() ) |
377 |
|
player.seekTime(position) |
378 |
|
|
|
if xbmc.Player().isPlaying(): |
|
|
if os.path.isfile(subtitlesfile): |
|
|
player.setSubtitles(subtitlesfile) |
|
|
print 'TODIC started subtitles' |
|
|
else: |
|
|
player.disableSubtitles() |
|
379 |
|
|
380 |
# player.callbackLoop() |
#Holder python kørernde indtil at det bliver bedt om at stoppe |
381 |
|
while (not xbmc.abortRequested): |
382 |
|
player.tick() |
383 |
|
xbmc.sleep(500) |
384 |
|
|
385 |
|
|
386 |
|
|
387 |
def search(): |
def search(): |
388 |
search = getUserInput("Todic Søgning") |
search = getUserInput("Todic Søgning") |
389 |
|
|
390 |
if (search != None and search != ""): |
if (search != None and search != ""): |
391 |
url = __backend__ + "&action=search&search=" + urllib.quote_plus(search) |
url = __backend__ + "&action=search&search=" + \ |
392 |
|
urllib.quote_plus(search) |
393 |
|
|
394 |
#print "[TODIC] Search start: " + search |
# print "[Todic] Search start: " + search |
395 |
#print "[TODIC] Search url: " + url |
# print "[Todic] Search url: " + url |
396 |
|
|
397 |
buildList(url, "søgning") |
buildList(url, "søgning") |
398 |
|
|
|
def searchSeries(): |
|
|
search = getUserInput("Todic Serie Søgning") |
|
399 |
|
|
400 |
if (search != None and search != ""): |
def searchSeries(): |
401 |
url = __backend__ + "&action=searchseries&search=" + urllib.quote_plus(search) |
search = getUserInput("Todic Serie Søgning") |
402 |
|
|
403 |
#print "[TODIC] Search start: " + search |
if (search != None and search != ""): |
404 |
#print "[TODIC] Search url: " + url |
url = __backend__ + "&action=searchseries&search=" + \ |
405 |
|
urllib.quote_plus(search) |
406 |
|
|
407 |
buildList(url, "serie søgning") |
# print "[Todic] Search start: " + search |
408 |
|
# print "[Todic] Search url: " + url |
409 |
|
|
410 |
|
buildList(url, "serie søgning") |
411 |
|
|
412 |
|
|
413 |
|
#=================================== Tool Box ======================================= |
|
#=================================== Tool Box ======================================= |
|
414 |
# shows a more userfriendly notification |
# shows a more userfriendly notification |
415 |
def showMessage(heading, message): |
def showMessage(heading, message): |
416 |
duration = 15*1000 |
duration = 15 * 1000 |
417 |
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) ) |
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % |
418 |
|
(heading, message, duration)) |
419 |
|
|
420 |
|
|
421 |
# raise a keyboard for user input |
# raise a keyboard for user input |
422 |
def getUserInput(title = "Input", default="", hidden=False): |
def getUserInput(title="Input", default="", hidden=False): |
423 |
result = None |
result = None |
424 |
|
|
425 |
# Fix for when this functions is called with default=None |
# Fix for when this functions is called with default=None |
426 |
if not default: |
if not default: |
427 |
default = "" |
default = "" |
428 |
|
|
429 |
keyboard = xbmc.Keyboard(default, title) |
keyboard = xbmc.Keyboard(default, title) |
430 |
keyboard.setHiddenInput(hidden) |
keyboard.setHiddenInput(hidden) |
431 |
keyboard.doModal() |
keyboard.doModal() |
432 |
|
|
433 |
if keyboard.isConfirmed(): |
if keyboard.isConfirmed(): |
434 |
result = keyboard.getText() |
result = keyboard.getText() |
435 |
|
|
436 |
return result |
return result |
437 |
|
|
438 |
|
|
439 |
def get_params(): |
def get_params(): |
440 |
param=[] |
return parse_parameter_string(sys.argv[2]) |
441 |
paramstring=sys.argv[2] |
|
442 |
if len(paramstring)>=2: |
|
443 |
params=sys.argv[2] |
def parse_parameter_string(paramstring): |
444 |
cleanedparams=params.replace('?','') |
param = [] |
445 |
if (params[len(params)-1]=='/'): |
if len(paramstring) >= 2: |
446 |
params=params[0:len(params)-2] |
params = paramstring |
447 |
pairsofparams=cleanedparams.split('&') |
cleanedparams = params.replace('?', '') |
448 |
param={} |
if (params[len(params) - 1] == '/'): |
449 |
for i in range(len(pairsofparams)): |
params = params[0:len(params) - 2] |
450 |
splitparams={} |
pairsofparams = cleanedparams.split('&') |
451 |
splitparams=pairsofparams[i].split('=') |
param = {} |
452 |
if (len(splitparams))==2: |
for i in range(len(pairsofparams)): |
453 |
param[splitparams[0]]=splitparams[1] |
splitparams = {} |
454 |
return param |
splitparams = pairsofparams[i].split('=') |
455 |
|
if (len(splitparams)) == 2: |
456 |
|
param[splitparams[0]] = splitparams[1] |
457 |
|
return param |
458 |
|
|
459 |
|
|
460 |
params = get_params() |
params = get_params() |
461 |
url = None |
url = None |
462 |
name = None |
name = None |
463 |
mode = None |
mode = None |
464 |
|
description = None |
465 |
|
|
466 |
|
|
467 |
|
#print params |
468 |
|
|
469 |
try: |
try: |
470 |
url = urllib.unquote_plus(params["url"]) |
url = urllib.unquote_plus(params["url"]) |
471 |
except: |
except: |
472 |
pass |
pass |
473 |
try: |
try: |
474 |
name = urllib.unquote_plus(params["name"]) |
name = urllib.unquote_plus(params["name"]) |
475 |
except: |
except: |
476 |
pass |
pass |
477 |
try: |
try: |
478 |
mode = int(params["mode"]) |
mode = int(params["mode"]) |
479 |
except: |
except: |
480 |
pass |
pass |
481 |
|
try: |
482 |
|
description = urllib.unquote_plus(params["description"]) |
483 |
|
except: |
484 |
|
pass |
485 |
|
|
486 |
|
|
487 |
|
|
488 |
|
|
489 |
|
try: |
490 |
|
open_url("http://todic.dk") |
491 |
|
except: |
492 |
|
showMessage("Fejl", "Kunne ikke forbinde til todic.dk") |
493 |
|
exit() |
494 |
|
|
495 |
|
|
496 |
if url == 'refresh': |
if url == 'refresh': |
497 |
#xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12 |
# xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker |
498 |
xbmc.executebuiltin("Container.Refresh") |
# ikke med XBMC12 |
499 |
|
xbmc.executebuiltin("Container.Refresh") |
500 |
|
|
501 |
|
|
502 |
elif mode == None: |
elif mode == None: |
503 |
#build main menu |
# build main menu |
504 |
rootMenu() |
rootMenu() |
505 |
|
|
506 |
elif mode == 1: |
elif mode == 1: |
507 |
#build list of movie starting letters |
# build list of movie starting letters |
508 |
buildList(url, name) |
buildList(url, name) |
509 |
|
|
510 |
elif mode == 10: |
elif mode == 10: |
511 |
search() |
search() |
512 |
|
|
513 |
elif mode == 11: |
elif mode == 11: |
514 |
searchSeries() |
searchSeries() |
|
|
|
|
|
|
|
elif mode == 50: |
|
|
play_video(url, name) |
|
|
|
|
|
|
|
515 |
|
|
516 |
|
|
517 |
|
elif mode == 50: |
518 |
|
play_video(url, name, description) |