1 |
|
|
2 |
|
# This Python file uses the following encoding: utf-8 |
3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 0.0.2 |
Version 0.0.15 |
7 |
''' |
''' |
8 |
|
|
9 |
import sys |
import sys |
16 |
import xbmcgui |
import xbmcgui |
17 |
import xbmcplugin |
import xbmcplugin |
18 |
import urllib |
import urllib |
19 |
import urllib2, re |
import urllib2 |
20 |
|
|
21 |
|
# import pprint |
22 |
|
|
23 |
|
from xml.dom.minidom import parseString |
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__ = "http://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( |
30 |
|
'special://profile/addon_data/plugin.video.todic/') |
31 |
|
|
32 |
def open_url(url): |
ADDON_PATH = __addon__.getAddonInfo('path') |
33 |
req = urllib2.Request(url) |
SkinMasterPath = os.path.join(ADDON_PATH, 'skins') + '/' |
34 |
content = urllib2.urlopen(req) |
MySkinPath = (os.path.join(SkinMasterPath, '720p')) + '/' |
35 |
data = content.read() |
MySkin = 'main.xml' |
|
content.close() |
|
|
return data |
|
36 |
|
|
|
def rootMenu(): |
|
37 |
|
|
38 |
buildList(__backend__, "", False) # call default list |
class TodicMovieDialog(xbmcgui.WindowXMLDialog): |
39 |
|
|
40 |
|
def __new__(cls): |
41 |
|
return super(TodicMovieDialog, cls).__new__(cls, "main.xml", ADDON_PATH) |
42 |
|
|
43 |
|
def __init__(self): |
44 |
|
super(TodicMovieDialog, self).__init__() |
45 |
|
|
46 |
|
def onClick(self, controlId): |
47 |
|
print "OnClick: " + str(controlId) |
48 |
|
|
49 |
|
if (controlId == 50): |
50 |
|
self.close() |
51 |
|
play_real_video(self.url, self.name) |
52 |
|
|
53 |
|
if (controlId == 98): |
54 |
|
self.close() |
55 |
|
|
56 |
|
def onInit(self): |
57 |
|
|
58 |
|
print "ONINIT" |
59 |
|
self.getControl(1).setLabel(self.name) |
60 |
|
self.getControl(2).setLabel(self.moviegroups) |
61 |
|
self.getControl(3).setLabel(self.description) |
62 |
|
self.getControl(10).setLabel(self.playlength) |
63 |
|
self.getControl(11).setLabel(self.codecdetails) |
64 |
|
|
65 |
|
orig_img_width = self.getControl(40).getWidth() |
66 |
|
self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width |
67 |
|
self.getControl(40).setWidth(int(self.starwidth)) |
68 |
|
|
69 |
|
def setUrl(self, url): |
70 |
|
print "SETURL:" + url |
71 |
|
self.url = url |
72 |
|
self.fetchClipDetails() |
73 |
|
|
74 |
# Adde xtra items to root menu |
def fetchClipDetails(self): |
75 |
listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') |
param1 = parse_parameter_string(self.url) |
|
listitem.setProperty('Fanart_Image', fanartImage) |
|
76 |
|
|
77 |
u = sys.argv[0] + "?mode=10&name=" |
self.clipkey = param1["clipkey"] |
78 |
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) |
print "CLIPKEY:" + self.clipkey |
79 |
|
detailurl = __backend__ + "&action=clipdetails&clipkey=" + self.clipkey |
80 |
|
|
81 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
xml = open_url(detailurl) |
82 |
|
|
83 |
|
doc = parseString(xml) |
84 |
|
self.imdbrating = getText(doc.getElementsByTagName("imdbrating")) |
85 |
|
self.moviegroups = getText(doc.getElementsByTagName("moviegroups")) |
86 |
|
self.playlength = getText(doc.getElementsByTagName("playlength")) |
87 |
|
self.codecdetails = getText(doc.getElementsByTagName("codecdetails")) |
88 |
|
|
89 |
def buildList(url,title, endlist=True): |
def setName(self, name): |
90 |
print '[TODIC]:'+str(url) |
self.name = name |
|
link = open_url(url) |
|
|
ty=re.compile('<meta type=\'(.+?)\'').findall(link) |
|
|
print '[TODIC]'+str(ty[0]) |
|
91 |
|
|
92 |
if ty[0] == 'clipList': |
def setDescription(self, description): |
93 |
mode = '50' |
self.description = description |
94 |
folder = False |
|
95 |
|
|
96 |
|
class TodicPlayer(xbmc.Player): |
97 |
|
|
98 |
|
def __init__(self, *args, **kwargs): |
99 |
|
# xbmc.Player.__init__(selv,*args,**kwargs) |
100 |
|
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) |
101 |
|
self.stopped = False |
102 |
|
self.started = False |
103 |
|
print "[TodicPlayer] init" |
104 |
|
|
105 |
|
# @catchall |
106 |
|
def onPlayBackStarted(self): |
107 |
|
self.started = True |
108 |
|
print "[TodicPlayer] : started" |
109 |
|
# super.onPlayBackStarted() |
110 |
|
|
111 |
|
def onPlayBackStopped(self): |
112 |
|
self.stopped = True |
113 |
|
print "[TodicPlayer] : stopped" |
114 |
|
|
115 |
|
def onPlayBackEnded(self): |
116 |
|
self.stopped = True |
117 |
|
print "[TodicPlayer] : ended" |
118 |
|
|
119 |
|
def callbackLoop(self): |
120 |
|
print "[Todic] startLoop" |
121 |
|
while (self.stopped == False): |
122 |
|
if (self.started == True): |
123 |
|
print "[todic] " + str(self.getTime()) |
124 |
|
xbmc.sleep(5000) |
125 |
|
|
126 |
|
|
127 |
|
def getText2(nodelist): |
128 |
|
rc = [] |
129 |
|
for node in nodelist: |
130 |
|
if node.nodeType == node.TEXT_NODE: |
131 |
|
rc.append(node.data) |
132 |
|
else: |
133 |
|
rc.append(getText(node.childNodes)) |
134 |
|
return ''.join(rc) |
135 |
|
|
136 |
|
|
137 |
|
def getText(nodelist): |
138 |
|
if nodelist.length == 0: |
139 |
|
return '' |
140 |
|
else: |
141 |
|
if nodelist[0].childNodes.length == 0: |
142 |
|
return '' |
143 |
else: |
else: |
144 |
mode = '1' |
return nodelist[0].childNodes[0].nodeValue |
145 |
folder = True |
|
146 |
|
|
147 |
|
def SaveFile(path, data): |
148 |
|
file = open(path, 'w') |
149 |
|
file.write(data) |
150 |
|
file.close() |
151 |
|
|
152 |
|
|
153 |
m=re.compile('<title>(.+?)</title><url>(.+?)</url><cover>(.+?)</cover><description>(.*)</description>').findall(link) |
def open_url(url): |
154 |
l=len(m) |
req = urllib2.Request(url) |
155 |
for name,url,thumb,description in m: |
content = urllib2.urlopen(req) |
156 |
|
data = content.read() |
157 |
listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) |
content.close() |
158 |
listitem.setProperty('Fanart_Image', fanartImage) |
return data |
159 |
if mode == '50': |
|
160 |
infoLabels = {} |
|
161 |
infoLabels['title'] = name |
def rootMenu(): |
|
infoLabels['plot'] = description |
|
|
listitem.setInfo('video', infoLabels) |
|
|
|
|
|
u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) |
|
|
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) |
|
|
|
|
|
if (endlist == True): |
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
|
162 |
|
|
163 |
|
msg = open_url(__backend__ + "&action=messages") |
164 |
|
msg = msg.strip() |
165 |
|
|
166 |
|
if msg != "": |
167 |
|
dialog = xbmcgui.Dialog() |
168 |
|
dialog.ok('XBMC Todic', msg) |
169 |
|
|
170 |
|
buildList(__backend__, "", False) # call default list |
171 |
|
|
172 |
|
# Adde xtra items to root menu |
173 |
|
listitem = xbmcgui.ListItem( |
174 |
|
label="Søg film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
175 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
176 |
|
|
177 |
|
u = sys.argv[0] + "?mode=10&name=" |
178 |
|
ok = xbmcplugin.addDirectoryItem( |
179 |
|
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
180 |
|
|
181 |
|
# add search series |
182 |
|
listitem = xbmcgui.ListItem( |
183 |
|
label="Søg Serier ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
184 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
185 |
|
|
186 |
|
u = sys.argv[0] + "?mode=11&name=" |
187 |
|
ok = xbmcplugin.addDirectoryItem( |
188 |
|
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
189 |
|
|
190 |
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
191 |
|
|
192 |
|
|
193 |
|
def buildList(url, title, endlist=True): |
194 |
|
print '[TODIC]:' + str(url) |
195 |
|
|
196 |
|
link = open_url(url) |
197 |
|
doc = parseString(link) |
198 |
|
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
199 |
|
print '[TODIC]' + str(ty) |
200 |
|
|
201 |
|
if ty == 'clipList': |
202 |
|
mode = '50' |
203 |
|
folder = False |
204 |
|
else: |
205 |
|
mode = '1' |
206 |
|
folder = True |
207 |
|
|
208 |
|
entries = doc.getElementsByTagName("entry") |
209 |
|
l = len(entries) |
210 |
|
description = '' |
211 |
|
for entry in entries: |
212 |
|
name = getText(entry.getElementsByTagName("title")) |
213 |
|
url = getText(entry.getElementsByTagName("url")) |
214 |
|
thumb = getText(entry.getElementsByTagName("cover")) |
215 |
|
description = getText(entry.getElementsByTagName("description")) |
216 |
|
playcount = getText(entry.getElementsByTagName("playcount")) |
217 |
|
|
218 |
|
if playcount == '': |
219 |
|
playcount = '0' |
220 |
|
playcount = int(playcount) |
221 |
|
|
222 |
|
# print "name:" + name |
223 |
|
# print "url:" + url |
224 |
|
# print "thumb:" + thumb |
225 |
|
# print "description:" + description |
226 |
|
listitem = xbmcgui.ListItem( |
227 |
|
label=name, label2='test', iconImage='DefaultFolder.png', thumbnailImage=thumb) |
228 |
|
listitem.setProperty('Fanart_Image', fanartImage) |
229 |
|
if mode == '50': |
230 |
|
infoLabels = {} |
231 |
|
infoLabels['title'] = name |
232 |
|
infoLabels['plot'] = description |
233 |
|
infoLabels['playcount'] = playcount |
234 |
|
listitem.setInfo('video', infoLabels) |
235 |
|
|
236 |
|
name = name.encode('UTF-8') |
237 |
|
description = description.encode('UTF-8') |
238 |
|
|
239 |
|
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
240 |
|
name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) |
241 |
|
ok = xbmcplugin.addDirectoryItem( |
242 |
|
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=folder, totalItems=l) |
243 |
|
|
244 |
|
if (endlist == True): |
245 |
|
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
246 |
|
|
247 |
|
|
248 |
|
def play_video(url, name, description): |
249 |
|
if (description == None or description == ""): |
250 |
|
play_real_video(url, name) |
251 |
|
else: |
252 |
|
d = TodicMovieDialog() |
253 |
|
d.setUrl(url) |
254 |
|
d.setName(name) |
255 |
|
d.setDescription(description) |
256 |
|
|
257 |
|
d.doModal() |
258 |
|
|
259 |
|
|
260 |
|
def play_real_video(url, name): |
261 |
|
xml = open_url(url) |
262 |
|
print 'TODIC url: ' + str(url) |
263 |
|
print 'TODIC xml: ' + xml |
264 |
|
|
265 |
|
doc = parseString(xml) |
266 |
|
url = getText(doc.getElementsByTagName("url")) |
267 |
|
|
268 |
|
subtitleurl = getText(doc.getElementsByTagName("subtitles")) |
269 |
|
subtitlesfile = os.path.join(datapath, 'temp.srt') |
270 |
|
|
271 |
|
# if old srt file exists delete it first |
272 |
|
if os.path.isfile(subtitlesfile): |
273 |
|
os.unlink(subtitlesfile) |
274 |
|
|
275 |
|
print '[TODIC] subs: ' + str(subtitleurl) |
276 |
|
if len(subtitleurl) > 0: |
277 |
|
subtitles = open_url(subtitleurl) |
278 |
|
SaveFile(subtitlesfile, subtitles) |
279 |
|
print 'TODIC downloaded subtitles' |
280 |
|
|
281 |
|
image = xbmc.getInfoImage('ListItem.Thumb') |
282 |
|
listitem = xbmcgui.ListItem( |
283 |
|
label=name, iconImage='DefaultVideo.png', thumbnailImage=image) |
284 |
|
listitem.setInfo(type="Video", infoLabels={"Title": name}) |
285 |
|
|
286 |
|
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
287 |
|
player.play(str(url), listitem) |
288 |
|
|
289 |
|
# kan ikke loade subtitles hvis foerend playeren koerer |
290 |
|
count = 0 |
291 |
|
while not xbmc.Player().isPlaying(): |
292 |
|
xbmc.sleep(500) |
293 |
|
count += 1 |
294 |
|
if count > 10: |
295 |
|
break |
296 |
|
|
297 |
|
if xbmc.Player().isPlaying(): |
298 |
|
if os.path.isfile(subtitlesfile): |
299 |
|
player.setSubtitles(subtitlesfile) |
300 |
|
print 'TODIC started subtitles' |
301 |
|
else: |
302 |
|
player.disableSubtitles() |
303 |
|
|
304 |
|
# player.callbackLoop() |
305 |
|
|
|
def play_video(url, name): |
|
|
link = open_url(url) |
|
|
match=re.compile('<url>(.+?)</url>').findall(link) |
|
|
url = match[0] |
|
|
print '[TODIC]:'+str(url) |
|
|
image = xbmc.getInfoImage( 'ListItem.Thumb' ) |
|
|
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image) |
|
|
# listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png') |
|
|
listitem.setInfo( type = "Video", infoLabels={ "Title": name } ) |
|
|
xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem) |
|
|
xbmc.sleep(200) |
|
306 |
|
|
307 |
def search(): |
def search(): |
308 |
search = getUserInput("Todic Søgning") |
search = getUserInput("Todic Søgning") |
309 |
|
|
310 |
|
if (search != None and search != ""): |
311 |
|
url = __backend__ + "&action=search&search=" + \ |
312 |
|
urllib.quote_plus(search) |
313 |
|
|
314 |
|
# print "[TODIC] Search start: " + search |
315 |
|
# print "[TODIC] Search url: " + url |
316 |
|
|
317 |
|
buildList(url, "søgning") |
318 |
|
|
|
if (search != None and search != ""): |
|
|
url = __backend__ + "&action=search&search=" + urllib.quote_plus(search) |
|
319 |
|
|
320 |
#print "[TODIC] Search start: " + search |
def searchSeries(): |
321 |
#print "[TODIC] Search url: " + url |
search = getUserInput("Todic Serie Søgning") |
322 |
|
|
323 |
buildList(url, "søgning") |
if (search != None and search != ""): |
324 |
|
url = __backend__ + "&action=searchseries&search=" + \ |
325 |
|
urllib.quote_plus(search) |
326 |
|
|
327 |
|
# print "[TODIC] Search start: " + search |
328 |
|
# print "[TODIC] Search url: " + url |
329 |
|
|
330 |
|
buildList(url, "serie søgning") |
331 |
|
|
332 |
|
|
333 |
#=================================== Tool Box ======================================= |
#=================================== Tool Box ======================================= |
334 |
# shows a more userfriendly notification |
# shows a more userfriendly notification |
335 |
def showMessage(heading, message): |
def showMessage(heading, message): |
336 |
duration = 15*1000 |
duration = 15 * 1000 |
337 |
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) ) |
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % |
338 |
|
(heading, message, duration)) |
339 |
|
|
340 |
|
|
341 |
# raise a keyboard for user input |
# raise a keyboard for user input |
342 |
def getUserInput(title = "Input", default="", hidden=False): |
def getUserInput(title="Input", default="", hidden=False): |
343 |
result = None |
result = None |
344 |
|
|
345 |
|
# Fix for when this functions is called with default=None |
346 |
|
if not default: |
347 |
|
default = "" |
348 |
|
|
349 |
|
keyboard = xbmc.Keyboard(default, title) |
350 |
|
keyboard.setHiddenInput(hidden) |
351 |
|
keyboard.doModal() |
352 |
|
|
353 |
|
if keyboard.isConfirmed(): |
354 |
|
result = keyboard.getText() |
355 |
|
|
356 |
# Fix for when this functions is called with default=None |
return result |
|
if not default: |
|
|
default = "" |
|
|
|
|
|
keyboard = xbmc.Keyboard(default, title) |
|
|
keyboard.setHiddenInput(hidden) |
|
|
keyboard.doModal() |
|
|
|
|
|
if keyboard.isConfirmed(): |
|
|
result = keyboard.getText() |
|
|
|
|
|
return result |
|
357 |
|
|
358 |
|
|
359 |
def get_params(): |
def get_params(): |
360 |
param=[] |
return parse_parameter_string(sys.argv[2]) |
361 |
paramstring=sys.argv[2] |
|
362 |
if len(paramstring)>=2: |
|
363 |
params=sys.argv[2] |
def parse_parameter_string(paramstring): |
364 |
cleanedparams=params.replace('?','') |
param = [] |
365 |
if (params[len(params)-1]=='/'): |
if len(paramstring) >= 2: |
366 |
params=params[0:len(params)-2] |
params = paramstring |
367 |
pairsofparams=cleanedparams.split('&') |
cleanedparams = params.replace('?', '') |
368 |
param={} |
if (params[len(params) - 1] == '/'): |
369 |
for i in range(len(pairsofparams)): |
params = params[0:len(params) - 2] |
370 |
splitparams={} |
pairsofparams = cleanedparams.split('&') |
371 |
splitparams=pairsofparams[i].split('=') |
param = {} |
372 |
if (len(splitparams))==2: |
for i in range(len(pairsofparams)): |
373 |
param[splitparams[0]]=splitparams[1] |
splitparams = {} |
374 |
return param |
splitparams = pairsofparams[i].split('=') |
375 |
|
if (len(splitparams)) == 2: |
376 |
|
param[splitparams[0]] = splitparams[1] |
377 |
|
return param |
378 |
|
|
|
params = get_params() |
|
|
url = None |
|
|
name = None |
|
|
mode = None |
|
379 |
|
|
380 |
params = get_params() |
params = get_params() |
381 |
url = None |
url = None |
382 |
name = None |
name = None |
383 |
mode = None |
mode = None |
384 |
|
description = None |
385 |
|
|
386 |
try: |
try: |
387 |
url = urllib.unquote_plus(params["url"]) |
url = urllib.unquote_plus(params["url"]) |
388 |
|
except: |
389 |
|
pass |
390 |
|
try: |
391 |
|
name = urllib.unquote_plus(params["name"]) |
392 |
except: |
except: |
393 |
pass |
pass |
394 |
try: |
try: |
395 |
name = urllib.unquote_plus(params["name"]) |
mode = int(params["mode"]) |
396 |
except: |
except: |
397 |
pass |
pass |
398 |
try: |
try: |
399 |
mode = int(params["mode"]) |
description = urllib.unquote_plus(params["description"]) |
400 |
except: |
except: |
401 |
pass |
pass |
402 |
|
|
403 |
|
try: |
404 |
|
open_url("http://todic.dk") |
405 |
|
except: |
406 |
|
showMessage("Fejl", "Kunne ikke forbinde til todic.dk") |
407 |
|
exit() |
408 |
|
|
|
if mode == None: |
|
|
#build main menu |
|
|
rootMenu() |
|
|
|
|
|
elif mode == 1: |
|
|
#build list of movie starting letters |
|
|
buildList(url, name) |
|
409 |
|
|
410 |
elif mode == 10: |
if url == 'refresh': |
411 |
search() |
# xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker |
412 |
|
# ikke med XBMC12 |
413 |
|
xbmc.executebuiltin("Container.Refresh") |
414 |
|
|
|
elif mode == 50: |
|
|
play_video(url, name) |
|
415 |
|
|
416 |
|
elif mode == None: |
417 |
|
# build main menu |
418 |
|
rootMenu() |
419 |
|
|
420 |
|
elif mode == 1: |
421 |
|
# build list of movie starting letters |
422 |
|
buildList(url, name) |
423 |
|
|
424 |
# xbmcplugin.endOfDirectory(int(sys.argv[1])) |
elif mode == 10: |
425 |
|
search() |
426 |
|
|
427 |
|
elif mode == 11: |
428 |
|
searchSeries() |
429 |
|
|
430 |
|
|
431 |
|
elif mode == 50: |
432 |
|
play_video(url, name, description) |