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