3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 0.0.15 |
Version 0.1.3 |
7 |
''' |
''' |
8 |
|
|
9 |
import sys |
import sys |
|
import cgi as urlparse |
|
10 |
import os |
import os |
11 |
|
|
12 |
|
|
20 |
# import pprint |
# 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'), 'movie_bg_blur.jpg') |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
29 |
datapath = xbmc.translatePath( |
datapath = xbmc.translatePath( |
30 |
'special://profile/addon_data/plugin.video.todic/') |
'special://profile/addon_data/plugin.video.todic/') |
42 |
|
|
43 |
def __init__(self): |
def __init__(self): |
44 |
super(TodicMovieDialog, self).__init__() |
super(TodicMovieDialog, self).__init__() |
45 |
|
self.position = 0 |
46 |
|
|
47 |
def onClick(self, controlId): |
def onClick(self, controlId): |
48 |
print "OnClick: " + str(controlId) |
print "[Todic] MovieDialog OnClick: " + str(controlId) |
49 |
|
|
50 |
if (controlId == 50): |
if (controlId == 50): |
51 |
self.close() |
self.close() |
52 |
play_real_video(self.url, self.name) |
play_real_video(self.url, self.name, 0) |
53 |
|
|
54 |
|
if (controlId == 51): |
55 |
|
self.close() |
56 |
|
play_real_video(self.url, self.name, self.position) |
57 |
|
|
58 |
if (controlId == 98): |
if (controlId == 98): |
59 |
self.close() |
self.close() |
60 |
|
|
61 |
def onInit(self): |
def onInit(self): |
62 |
|
|
63 |
print "ONINIT" |
print "[Todic] MovieDialog onInit" |
64 |
self.getControl(1).setLabel(self.name) |
self.getControl(1).setLabel(self.name) |
65 |
self.getControl(2).setLabel(self.moviegroups) |
self.getControl(2).setLabel(self.moviegroups) |
66 |
self.getControl(3).setLabel(self.description) |
self.getControl(3).setLabel(self.description) |
67 |
self.getControl(10).setLabel(self.playlength) |
self.getControl(10).setLabel(self.playlength) |
68 |
self.getControl(11).setLabel(self.codecdetails) |
self.getControl(11).setLabel(self.codecdetails) |
69 |
|
|
70 |
orig_img_width = self.getControl(40).getWidth() |
if (self.position > 0): |
71 |
self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width |
self.getControl(51).setVisible(True) |
72 |
self.getControl(40).setWidth(int(self.starwidth)) |
self.getControl(50).setPosition(100, 570) |
73 |
|
self.getControl(51).setPosition(450, 570) |
74 |
|
self.getControl(50).controlLeft( self.getControl(51) ) |
75 |
|
self.getControl(50).controlRight( self.getControl(51) ) |
76 |
|
else: |
77 |
|
self.getControl(51).setVisible(False) |
78 |
|
|
79 |
|
#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 |
def setUrl(self, url): |
def setUrl(self, url): |
|
print "SETURL:" + url |
|
92 |
self.url = url |
self.url = url |
|
self.fetchClipDetails() |
|
|
|
|
|
def fetchClipDetails(self): |
|
|
param1 = parse_parameter_string(self.url) |
|
|
|
|
|
self.clipkey = param1["clipkey"] |
|
|
print "CLIPKEY:" + self.clipkey |
|
|
detailurl = __backend__ + "&action=clipdetails&clipkey=" + self.clipkey |
|
|
|
|
|
xml = open_url(detailurl) |
|
|
|
|
|
doc = parseString(xml) |
|
|
self.imdbrating = getText(doc.getElementsByTagName("imdbrating")) |
|
|
self.moviegroups = getText(doc.getElementsByTagName("moviegroups")) |
|
|
self.playlength = getText(doc.getElementsByTagName("playlength")) |
|
|
self.codecdetails = getText(doc.getElementsByTagName("codecdetails")) |
|
93 |
|
|
94 |
def setName(self, name): |
def setName(self, name): |
95 |
self.name = name |
self.name = name |
105 |
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) |
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) |
106 |
self.stopped = False |
self.stopped = False |
107 |
self.started = False |
self.started = False |
108 |
|
self.playingPosition = 0.0 |
109 |
|
self.lastReport = 0 |
110 |
print "[TodicPlayer] init" |
print "[TodicPlayer] init" |
111 |
|
|
|
# @catchall |
|
112 |
def onPlayBackStarted(self): |
def onPlayBackStarted(self): |
113 |
self.started = True |
self.started = True |
114 |
print "[TodicPlayer] : started" |
print "[TodicPlayer] : started" |
|
# super.onPlayBackStarted() |
|
115 |
|
|
116 |
|
#When user presses stop, we report back the the position registered in the last call to self.tick() |
117 |
def onPlayBackStopped(self): |
def onPlayBackStopped(self): |
118 |
self.stopped = True |
self.stopped = True |
119 |
print "[TodicPlayer] : stopped" |
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): |
def onPlayBackEnded(self): |
132 |
self.stopped = True |
self.stopped = True |
133 |
print "[TodicPlayer] : ended" |
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 callbackLoop(self): |
|
|
print "[Todic] startLoop" |
|
|
while (self.stopped == False): |
|
|
if (self.started == True): |
|
|
print "[todic] " + str(self.getTime()) |
|
|
xbmc.sleep(5000) |
|
152 |
|
|
153 |
|
|
154 |
def getText2(nodelist): |
def getText2(nodelist): |
171 |
return nodelist[0].childNodes[0].nodeValue |
return nodelist[0].childNodes[0].nodeValue |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
def SaveFile(path, data): |
def SaveFile(path, data): |
176 |
file = open(path, 'w') |
file = open(path, 'w') |
177 |
file.write(data) |
file.write(data) |
178 |
file.close() |
file.close() |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
def open_url(url): |
def open_url(url): |
183 |
req = urllib2.Request(url) |
req = urllib2.Request(url) |
184 |
content = urllib2.urlopen(req) |
content = urllib2.urlopen(req) |
187 |
return data |
return data |
188 |
|
|
189 |
|
|
190 |
|
# wraps open url in a catch-all exception handler |
191 |
|
# 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 |
|
|
198 |
|
|
199 |
|
|
200 |
def rootMenu(): |
def rootMenu(): |
201 |
|
|
202 |
msg = open_url(__backend__ + "&action=messages") |
msg = open_url(__backend__ + "&action=messages") |
210 |
|
|
211 |
# Adde xtra items to root menu |
# Adde xtra items to root menu |
212 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
213 |
label="Søg film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
label="Søg Film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
214 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
215 |
|
|
216 |
u = sys.argv[0] + "?mode=10&name=" |
u = sys.argv[0] + "?mode=10&name=" |
217 |
ok = xbmcplugin.addDirectoryItem( |
xbmcplugin.addDirectoryItem( |
218 |
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
219 |
|
|
220 |
# add search series |
# add search series |
223 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
224 |
|
|
225 |
u = sys.argv[0] + "?mode=11&name=" |
u = sys.argv[0] + "?mode=11&name=" |
226 |
ok = xbmcplugin.addDirectoryItem( |
xbmcplugin.addDirectoryItem( |
227 |
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
228 |
|
|
229 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
230 |
|
|
231 |
|
|
232 |
def buildList(url, title, endlist=True): |
def buildList(url, title, endlist=True): |
233 |
print '[TODIC]:' + str(url) |
print '[Todic]:' + str(url) |
234 |
|
|
235 |
link = open_url(url) |
link = open_url(url) |
236 |
doc = parseString(link) |
doc = parseString(link) |
237 |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
238 |
print '[TODIC]' + str(ty) |
print '[Todic]' + str(ty) |
239 |
|
|
240 |
if ty == 'clipList': |
if ty == 'clipList': |
241 |
mode = '50' |
mode = '50' |
254 |
description = getText(entry.getElementsByTagName("description")) |
description = getText(entry.getElementsByTagName("description")) |
255 |
playcount = getText(entry.getElementsByTagName("playcount")) |
playcount = getText(entry.getElementsByTagName("playcount")) |
256 |
|
|
257 |
|
|
258 |
if playcount == '': |
if playcount == '': |
259 |
playcount = '0' |
playcount = '0' |
260 |
playcount = int(playcount) |
playcount = int(playcount) |
278 |
|
|
279 |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
280 |
name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) |
name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) |
281 |
ok = xbmcplugin.addDirectoryItem( |
xbmcplugin.addDirectoryItem( |
282 |
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=folder, totalItems=l) |
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=folder, totalItems=l) |
283 |
|
|
284 |
if (endlist == True): |
if (endlist == True): |
286 |
|
|
287 |
|
|
288 |
def play_video(url, name, description): |
def play_video(url, name, description): |
289 |
|
playPosition = 0 |
290 |
|
savedPosition = 0 |
291 |
|
try: |
292 |
|
param1 = parse_parameter_string(url) |
293 |
|
clipkey = param1["clipkey"] |
294 |
|
|
295 |
|
print "[Todic] ClipKey:" + clipkey |
296 |
|
detailurl = __backend__ + "&action=clipdetails&clipkey=" + clipkey |
297 |
|
print "[Todic] detailURL = " + detailurl |
298 |
|
|
299 |
|
xml = open_url(detailurl) |
300 |
|
|
301 |
|
clipDetailsDoc = parseString(xml) |
302 |
|
savedPosition = int( getText(clipDetailsDoc.getElementsByTagName("position")) ) |
303 |
|
except: |
304 |
|
print "[Todic] Unexpected error:", sys.exc_info()[0] |
305 |
|
|
306 |
if (description == None or description == ""): |
if (description == None or description == ""): |
307 |
play_real_video(url, name) |
if (savedPosition > 0): |
308 |
|
dialog = xbmcgui.Dialog() |
309 |
|
#yes / true -afspil fra position |
310 |
|
answer = dialog.yesno(heading='Todic', line1='Afspil fra sidste position', nolabel='Fra start', yeslabel='Fortsæt') |
311 |
|
if (answer == True): |
312 |
|
playPosition = savedPosition |
313 |
|
|
314 |
|
play_real_video(url, name, playPosition) |
315 |
|
|
316 |
else: |
else: |
317 |
d = TodicMovieDialog() |
d = TodicMovieDialog() |
318 |
d.setUrl(url) |
d.setDetailsDoc(clipDetailsDoc) |
319 |
d.setName(name) |
d.setName(name) |
320 |
|
d.setUrl(url) |
321 |
d.setDescription(description) |
d.setDescription(description) |
322 |
|
|
323 |
d.doModal() |
d.doModal() |
324 |
|
|
325 |
|
|
326 |
def play_real_video(url, name): |
def play_real_video(url, name, position): |
327 |
xml = open_url(url) |
xml = open_url(url) |
328 |
print 'TODIC url: ' + str(url) |
print '[Todic] url: ' + str(url) |
329 |
print 'TODIC xml: ' + xml |
print '[Todic] xml: ' + xml |
330 |
|
print '[Todic] pos: ' + str(position) |
331 |
|
|
332 |
doc = parseString(xml) |
doc = parseString(xml) |
333 |
url = getText(doc.getElementsByTagName("url")) |
url = getText(doc.getElementsByTagName("url")) |
339 |
if os.path.isfile(subtitlesfile): |
if os.path.isfile(subtitlesfile): |
340 |
os.unlink(subtitlesfile) |
os.unlink(subtitlesfile) |
341 |
|
|
342 |
print '[TODIC] subs: ' + str(subtitleurl) |
print '[Todic] subs: ' + str(subtitleurl) |
343 |
if len(subtitleurl) > 0: |
if len(subtitleurl) > 0: |
344 |
subtitles = open_url(subtitleurl) |
subtitles = open_url(subtitleurl) |
345 |
SaveFile(subtitlesfile, subtitles) |
SaveFile(subtitlesfile, subtitles) |
346 |
print 'TODIC downloaded subtitles' |
print '[Todic] downloaded subtitles' |
347 |
|
|
348 |
image = xbmc.getInfoImage('ListItem.Thumb') |
image = xbmc.getInfoImage('ListItem.Thumb') |
349 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
350 |
label=name, iconImage='DefaultVideo.png', thumbnailImage=image) |
label=name, iconImage='DefaultVideo.png', thumbnailImage=image) |
351 |
listitem.setInfo(type="Video", infoLabels={"Title": name}) |
listitem.setInfo(type="Video", infoLabels={"Title": name}) |
352 |
|
listitem.setProperty('ResumeTime', '300') |
353 |
|
listitem.setProperty('TotalTime', '3000') |
354 |
|
|
355 |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
356 |
player.play(str(url), listitem) |
player.play(str(url), listitem) |
358 |
# kan ikke loade subtitles hvis foerend playeren koerer |
# kan ikke loade subtitles hvis foerend playeren koerer |
359 |
count = 0 |
count = 0 |
360 |
while not xbmc.Player().isPlaying(): |
while not xbmc.Player().isPlaying(): |
361 |
xbmc.sleep(500) |
xbmc.sleep(250) |
362 |
count += 1 |
count += 1 |
363 |
if count > 10: |
if count > 10: |
364 |
break |
break |
365 |
|
|
366 |
|
|
367 |
|
|
368 |
if xbmc.Player().isPlaying(): |
if xbmc.Player().isPlaying(): |
369 |
if os.path.isfile(subtitlesfile): |
if os.path.isfile(subtitlesfile): |
370 |
player.setSubtitles(subtitlesfile) |
player.setSubtitles(subtitlesfile) |
371 |
print 'TODIC started subtitles' |
print '[Todic] started subtitles' |
372 |
else: |
else: |
373 |
player.disableSubtitles() |
player.disableSubtitles() |
374 |
|
|
375 |
# player.callbackLoop() |
|
376 |
|
if (position > 0): |
377 |
|
while (player.getTotalTime() == 0.0): #Vent indtil vi har beregnet hvor langt klippet er |
378 |
|
xbmc.sleep(250) |
379 |
|
|
380 |
|
print "[Todic] totalTime " + str( player.getTotalTime() ) |
381 |
|
player.seekTime(position) |
382 |
|
|
383 |
|
|
384 |
|
#Holder python kørernde indtil at det bliver bedt om at stoppe |
385 |
|
while (not xbmc.abortRequested): |
386 |
|
player.tick() |
387 |
|
xbmc.sleep(500) |
388 |
|
|
389 |
|
|
390 |
|
|
391 |
def search(): |
def search(): |
395 |
url = __backend__ + "&action=search&search=" + \ |
url = __backend__ + "&action=search&search=" + \ |
396 |
urllib.quote_plus(search) |
urllib.quote_plus(search) |
397 |
|
|
398 |
# print "[TODIC] Search start: " + search |
# print "[Todic] Search start: " + search |
399 |
# print "[TODIC] Search url: " + url |
# print "[Todic] Search url: " + url |
400 |
|
|
401 |
buildList(url, "søgning") |
buildList(url, "søgning") |
402 |
|
|
408 |
url = __backend__ + "&action=searchseries&search=" + \ |
url = __backend__ + "&action=searchseries&search=" + \ |
409 |
urllib.quote_plus(search) |
urllib.quote_plus(search) |
410 |
|
|
411 |
# print "[TODIC] Search start: " + search |
# print "[Todic] Search start: " + search |
412 |
# print "[TODIC] Search url: " + url |
# print "[Todic] Search url: " + url |
413 |
|
|
414 |
buildList(url, "serie søgning") |
buildList(url, "serie søgning") |
415 |
|
|
467 |
mode = None |
mode = None |
468 |
description = None |
description = None |
469 |
|
|
470 |
|
|
471 |
|
#print params |
472 |
|
|
473 |
try: |
try: |
474 |
url = urllib.unquote_plus(params["url"]) |
url = urllib.unquote_plus(params["url"]) |
475 |
except: |
except: |
487 |
except: |
except: |
488 |
pass |
pass |
489 |
|
|
490 |
|
|
491 |
|
|
492 |
|
|
493 |
try: |
try: |
494 |
open_url("http://todic.dk") |
open_url("http://todic.dk") |
495 |
except: |
except: |