3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 1.7 |
Version 1.7.3 |
7 |
''' |
''' |
8 |
|
|
9 |
import sys |
import sys |
28 |
__backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__ |
__backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__ |
29 |
|
|
30 |
if __entrypoint__ == "alternative": |
if __entrypoint__ == "alternative": |
31 |
__backend__ = "https://alt.todic.dk/xbmc.php?xbmckey=" + __key__ |
__backend__ = "https://alt.todic.dk/xbmc.php?xbmckey=" + __key__ |
32 |
|
|
33 |
if __entrypoint__ == "testing": |
if __entrypoint__ == "testing": |
34 |
__backend__ = "https://todic.dk/xbmc-beta.php?xbmckey=" + __key__ |
__backend__ = "https://todic.dk/xbmc-beta.php?xbmckey=" + __key__ |
35 |
|
|
36 |
|
print( "[Todic] entrypoint: " + __entrypoint__ ) |
37 |
|
print( "[Todic] backend: " + __backend__ ) |
38 |
|
|
39 |
|
|
40 |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
57 |
self.position = 0 |
self.position = 0 |
58 |
|
|
59 |
def onClick(self, controlId): |
def onClick(self, controlId): |
60 |
print "[Todic] MovieDialog OnClick: " + str(controlId) |
print( "[Todic] MovieDialog OnClick: " + str(controlId) ) |
61 |
|
|
62 |
if (controlId == 50): |
if (controlId == 50): |
63 |
self.close() |
self.close() |
72 |
|
|
73 |
def onInit(self): |
def onInit(self): |
74 |
|
|
75 |
print "[Todic] MovieDialog onInit" |
print( "[Todic] MovieDialog onInit" ) |
76 |
self.getControl(1).setLabel(self.name) |
self.getControl(1).setLabel(self.name) |
77 |
self.getControl(2).setLabel(self.moviegroups) |
self.getControl(2).setLabel(self.moviegroups) |
78 |
self.getControl(3).setLabel(self.description) |
self.getControl(3).setLabel(self.description) |
93 |
#self.getControl(40).setWidth(int(self.starwidth)) |
#self.getControl(40).setWidth(int(self.starwidth)) |
94 |
|
|
95 |
def setDetailsDoc(self, detailsDoc): |
def setDetailsDoc(self, detailsDoc): |
96 |
print "[Todic] MovieDialog setDetailsDoc:" |
print( "[Todic] MovieDialog setDetailsDoc:") |
97 |
self.imdbrating = getText(detailsDoc.getElementsByTagName("imdbrating")) |
self.imdbrating = getText(detailsDoc.getElementsByTagName("imdbrating")) |
98 |
self.moviegroups = getText(detailsDoc.getElementsByTagName("moviegroups")) |
self.moviegroups = getText(detailsDoc.getElementsByTagName("moviegroups")) |
99 |
self.playlength = getText(detailsDoc.getElementsByTagName("playlength")) |
self.playlength = getText(detailsDoc.getElementsByTagName("playlength")) |
119 |
self.started = False |
self.started = False |
120 |
self.playingPosition = 0.0 |
self.playingPosition = 0.0 |
121 |
self.lastReport = 0 |
self.lastReport = 0 |
122 |
print "[TodicPlayer] init" |
print( "[TodicPlayer] init") |
123 |
|
|
124 |
def onPlayBackStarted(self): |
def onPlayBackStarted(self): |
125 |
self.started = True |
self.started = True |
126 |
print "[TodicPlayer] : started" |
print( "[TodicPlayer] : started") |
127 |
|
|
128 |
#When user presses stop, we report back the the position registered in the last call to self.tick() |
#When user presses stop, we report back the the position registered in the last call to self.tick() |
129 |
def onPlayBackStopped(self): |
def onPlayBackStopped(self): |
130 |
self.stopped = True |
self.stopped = True |
131 |
print "[TodicPlayer] : stopped" |
print( "[TodicPlayer] : stopped") |
132 |
self.reportPlaytime("stopped") |
self.reportPlaytime("stopped") |
133 |
|
|
134 |
def onPlayBackPaused(self): |
def onPlayBackPaused(self): |
135 |
print "[TodicPlayer] : paused" |
print( "[TodicPlayer] : paused") |
136 |
self.reportPlaytime("paused") |
self.reportPlaytime("paused") |
137 |
|
|
138 |
def onPlayBackResumed(self): |
def onPlayBackResumed(self): |
139 |
print "[TodicPlayer] : resumed" |
print( "[TodicPlayer] : resumed") |
140 |
self.reportPlaytime("resumed") |
self.reportPlaytime("resumed") |
141 |
|
|
142 |
|
|
143 |
def onPlayBackEnded(self): |
def onPlayBackEnded(self): |
144 |
self.stopped = True |
self.stopped = True |
145 |
print "[TodicPlayer] : ended" |
print( "[TodicPlayer] : ended") |
146 |
self.reportPlaytime("ended") |
self.reportPlaytime("ended") |
147 |
|
|
148 |
def tick(self): |
def tick(self): |
149 |
#print "[Todic] Tick: " + str( self.isPlaying() ) |
#print "[Todic] Tick: " + str( self.isPlaying() ) |
150 |
if ( self.isPlaying() ): |
if ( self.isPlaying() ): |
151 |
self.playingPosition = self.getTime() |
tmpTime = self.getTime() |
152 |
now = time() |
|
153 |
#print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) |
#only report time if it has changed in the mean time |
154 |
if ( (now - self.lastReport) > 60.0): |
if tmpTime != self.playingPosition: |
155 |
self.lastReport = now |
self.playingPosition = tmpTime |
156 |
self.reportPlaytime("playing") |
now = time() |
157 |
|
#print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) |
158 |
|
if ( (now - self.lastReport) > 60.0): |
159 |
|
self.lastReport = now |
160 |
|
self.reportPlaytime("playing") |
161 |
|
|
162 |
def reportPlaytime(self, subaction): |
def reportPlaytime(self, subaction): |
163 |
if (self.playingPosition > 60): |
if (self.playingPosition > 60): |
164 |
url = __backend__ + "&action=playbacktime&subaction=" + subaction + "&time=" + str( self.playingPosition ) |
url = __backend__ + "&action=playbacktime&subaction=" + subaction + "&time=" + str( self.playingPosition ) |
165 |
print "[Todic] reportPlaytime:" + url |
print( "[Todic] reportPlaytime:" + url) |
166 |
open_url_safe(url) |
open_url_safe(url) |
167 |
|
|
168 |
|
|
209 |
try: |
try: |
210 |
return open_url(url) |
return open_url(url) |
211 |
except: |
except: |
212 |
print "[Todic] Some error during open_url call to ", url |
print( "[Todic] Some error during open_url call to ", url) |
213 |
|
|
214 |
|
|
215 |
|
|
246 |
|
|
247 |
|
|
248 |
def buildList(url, title, endlist=True): |
def buildList(url, title, endlist=True): |
249 |
print '[Todic]:' + str(url) |
print( '[Todic]:' + str(url) ) |
250 |
|
|
251 |
link = open_url(url) |
link = open_url(url) |
252 |
doc = parseString(link) |
doc = parseString(link) |
253 |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
254 |
print '[Todic]' + str(ty) |
print( '[Todic]' + str(ty)) |
255 |
|
|
256 |
if ty == 'clipList': |
if ty == 'clipList': |
257 |
mode = '50' |
mode = '50' |
278 |
# print "url:" + url |
# print "url:" + url |
279 |
# print "thumb:" + thumb |
# print "thumb:" + thumb |
280 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
281 |
label=name, label2='test', iconImage='DefaultFolder.png', thumbnailImage=thumb) |
label=name, label2='test', iconImage='DefaultFolder.png') |
282 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
283 |
|
listitem.addContextMenuItems([('Refresh', 'Container.Refresh')]) |
284 |
|
|
285 |
if mode == '50': |
if mode == '50': |
286 |
infoLabels = {} |
infoLabels = {} |
287 |
infoLabels['title'] = name |
infoLabels['title'] = name |
288 |
infoLabels['playcount'] = playcount |
infoLabels['playcount'] = playcount |
289 |
|
if playcount > 0: |
290 |
|
listitem.setArt( {'thumb': thumb} ) #not pretty - but at least we can show a different icon for unwatched/watched in kodi18 |
291 |
listitem.setInfo('video', infoLabels) |
listitem.setInfo('video', infoLabels) |
292 |
|
listitem.setProperty('IsPlayable', 'true') |
293 |
|
|
294 |
name = name.encode('UTF-8') |
name = name.encode('UTF-8') |
295 |
|
|
310 |
param1 = parse_parameter_string(url) |
param1 = parse_parameter_string(url) |
311 |
clipkey = param1["clipkey"] |
clipkey = param1["clipkey"] |
312 |
|
|
313 |
print "[Todic] ClipKey:" + clipkey |
print( "[Todic] ClipKey:" + clipkey) |
314 |
detailurl = __backend__ + "&action=clipdetails&clipkey=" + clipkey |
detailurl = __backend__ + "&action=clipdetails&clipkey=" + clipkey |
315 |
print "[Todic] detailURL = " + detailurl |
print( "[Todic] detailURL = " + detailurl) |
316 |
|
|
317 |
xml = open_url(detailurl) |
xml = open_url(detailurl) |
318 |
|
|
320 |
savedPosition = int( getText(clipDetailsDoc.getElementsByTagName("position")) ) |
savedPosition = int( getText(clipDetailsDoc.getElementsByTagName("position")) ) |
321 |
description = getText(clipDetailsDoc.getElementsByTagName("description")) |
description = getText(clipDetailsDoc.getElementsByTagName("description")) |
322 |
except: |
except: |
323 |
print "[Todic] Unexpected error:", sys.exc_info()[0] |
print( "[Todic] Unexpected error:", sys.exc_info()[0] ) |
324 |
|
|
325 |
if (description == None or description == ""): |
if (description == None or description == ""): |
326 |
if (savedPosition > 0): |
if (savedPosition > 0): |
344 |
|
|
345 |
def play_real_video(url, name, position): |
def play_real_video(url, name, position): |
346 |
xml = open_url(url) |
xml = open_url(url) |
347 |
print '[Todic] url: ' + str(url) |
print( '[Todic] url: ' + str(url) ) |
348 |
print '[Todic] xml: ' + xml |
print( '[Todic] xml: ' + xml ) |
349 |
print '[Todic] pos: ' + str(position) |
print( '[Todic] pos: ' + str(position) ) |
350 |
|
|
351 |
doc = parseString(xml) |
doc = parseString(xml) |
352 |
url = getText(doc.getElementsByTagName("url")) |
url = getText(doc.getElementsByTagName("url")) |
353 |
|
|
354 |
subtitleurl = getText(doc.getElementsByTagName("subtitles")) |
subtitleurl = getText(doc.getElementsByTagName("subtitles")) |
|
subtitlesfile = os.path.join(datapath, 'temp.srt') |
|
355 |
|
|
|
# if old srt file exists delete it first |
|
|
if os.path.isfile(subtitlesfile): |
|
|
os.unlink(subtitlesfile) |
|
356 |
|
|
357 |
print '[Todic] subs: ' + str(subtitleurl) |
print( '[Todic] subs: ' + str(subtitleurl) ) |
|
if len(subtitleurl) > 0: |
|
|
subtitles = open_url(subtitleurl) |
|
|
SaveFile(subtitlesfile, subtitles) |
|
|
print '[Todic] downloaded subtitles' |
|
358 |
|
|
359 |
image = xbmc.getInfoImage('ListItem.Thumb') |
image = xbmc.getInfoImage('ListItem.Thumb') |
360 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
361 |
label=name, iconImage='DefaultVideo.png', thumbnailImage=image) |
label=name, iconImage='DefaultVideo.png', thumbnailImage=image) |
362 |
listitem.setInfo(type="Video", infoLabels={"Title": name}) |
listitem.setInfo(type="Video", infoLabels={"Title": name}) |
|
listitem.setProperty('ResumeTime', '300') |
|
|
listitem.setProperty('TotalTime', '3000') |
|
|
|
|
|
player = TodicPlayer() |
|
|
player.play(str(url), listitem) |
|
|
|
|
|
# kan ikke loade subtitles hvis foerend playeren koerer |
|
|
count = 0 |
|
|
while not xbmc.Player().isPlaying(): |
|
|
xbmc.sleep(250) |
|
|
count += 1 |
|
|
if count > 10: |
|
|
break |
|
363 |
|
|
364 |
|
listitem.setProperty('StartOffset', str(position) ) |
365 |
|
|
366 |
|
if len(subtitleurl) > 0: |
367 |
|
listitem.setSubtitles([subtitleurl]) |
368 |
|
|
369 |
if xbmc.Player().isPlaying(): |
player = TodicPlayer() |
370 |
if os.path.isfile(subtitlesfile): |
player.play(str(url), listitem) |
|
player.setSubtitles(subtitlesfile) |
|
|
print '[Todic] started subtitles' |
|
|
else: |
|
|
player.showSubtitles(False) |
|
|
|
|
|
|
|
|
if (position > 0): |
|
|
while (player.getTotalTime() == 0.0): #Vent indtil vi har beregnet hvor langt klippet er |
|
|
xbmc.sleep(250) |
|
|
|
|
|
print "[Todic] totalTime " + str( player.getTotalTime() ) |
|
|
player.seekTime(position) |
|
371 |
|
|
372 |
|
|
373 |
#Holder python kørernde indtil at det bliver bedt om at stoppe |
#Holder python kørernde indtil at det bliver bedt om at stoppe |