3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 0.0.20 |
Version 1.7.3 |
7 |
''' |
''' |
8 |
|
|
9 |
import sys |
import sys |
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 |
|
__entrypoint__ = __addon__.getSetting('entrypoint').lower() |
28 |
__backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__ |
__backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__ |
29 |
|
|
30 |
|
|
31 |
|
if __entrypoint__ == "alternative": |
32 |
|
__backend__ = "https://alt.todic.dk/xbmc.php?xbmckey=" + __key__ |
33 |
|
|
34 |
|
if __entrypoint__ == "testing": |
35 |
|
__backend__ = "https://todic.dk/xbmc-beta.php?xbmckey=" + __key__ |
36 |
|
|
37 |
|
print( "[Todic] entrypoint: " + __entrypoint__ ) |
38 |
|
print( "[Todic] backend: " + __backend__ ) |
39 |
|
|
40 |
|
|
41 |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
42 |
datapath = xbmc.translatePath( |
datapath = xbmc.translatePath( |
43 |
'special://profile/addon_data/plugin.video.todic/') |
'special://profile/addon_data/plugin.video.todic/') |
58 |
self.position = 0 |
self.position = 0 |
59 |
|
|
60 |
def onClick(self, controlId): |
def onClick(self, controlId): |
61 |
print "[Todic] MovieDialog OnClick: " + str(controlId) |
print( "[Todic] MovieDialog OnClick: " + str(controlId) ) |
62 |
|
|
63 |
if (controlId == 50): |
if (controlId == 50): |
64 |
self.close() |
self.close() |
73 |
|
|
74 |
def onInit(self): |
def onInit(self): |
75 |
|
|
76 |
print "[Todic] MovieDialog ONINIT" |
print( "[Todic] MovieDialog onInit" ) |
77 |
self.getControl(1).setLabel(self.name) |
self.getControl(1).setLabel(self.name) |
78 |
self.getControl(2).setLabel(self.moviegroups) |
self.getControl(2).setLabel(self.moviegroups) |
79 |
self.getControl(3).setLabel(self.description) |
self.getControl(3).setLabel(self.description) |
93 |
#self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width |
#self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width |
94 |
#self.getControl(40).setWidth(int(self.starwidth)) |
#self.getControl(40).setWidth(int(self.starwidth)) |
95 |
|
|
96 |
|
def setDetailsDoc(self, detailsDoc): |
97 |
|
print( "[Todic] MovieDialog setDetailsDoc:") |
98 |
|
self.imdbrating = getText(detailsDoc.getElementsByTagName("imdbrating")) |
99 |
|
self.moviegroups = getText(detailsDoc.getElementsByTagName("moviegroups")) |
100 |
|
self.playlength = getText(detailsDoc.getElementsByTagName("playlength")) |
101 |
|
self.codecdetails = getText(detailsDoc.getElementsByTagName("codecdetails")) |
102 |
|
self.position = int( getText(detailsDoc.getElementsByTagName("position")) ) |
103 |
|
|
104 |
def setUrl(self, url): |
def setUrl(self, url): |
|
print "[Todic] MovieDialog SETURL:" + url |
|
105 |
self.url = url |
self.url = url |
|
self.fetchClipDetails() |
|
|
|
|
|
def setPosition(self, pos): |
|
|
print "[Todic] MovieDialog setPosition:" + str(pos) |
|
|
self.position = pos |
|
|
|
|
|
|
|
|
|
|
|
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")) |
|
106 |
|
|
107 |
def setName(self, name): |
def setName(self, name): |
108 |
self.name = name |
self.name = name |
115 |
|
|
116 |
def __init__(self, *args, **kwargs): |
def __init__(self, *args, **kwargs): |
117 |
# xbmc.Player.__init__(selv,*args,**kwargs) |
# xbmc.Player.__init__(selv,*args,**kwargs) |
118 |
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) |
xbmc.Player.__init__(self) |
119 |
self.stopped = False |
self.stopped = False |
120 |
self.started = False |
self.started = False |
121 |
self.playingPosition = 0.0 |
self.playingPosition = 0.0 |
122 |
self.lastReport = 0 |
self.lastReport = 0 |
123 |
print "[TodicPlayer] init" |
print( "[TodicPlayer] init") |
124 |
|
|
|
# @catchall |
|
125 |
def onPlayBackStarted(self): |
def onPlayBackStarted(self): |
126 |
self.started = True |
self.started = True |
127 |
print "[TodicPlayer] : started" |
print( "[TodicPlayer] : started") |
|
# super.onPlayBackStarted() |
|
128 |
|
|
129 |
#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() |
130 |
def onPlayBackStopped(self): |
def onPlayBackStopped(self): |
131 |
self.stopped = True |
self.stopped = True |
132 |
print "[TodicPlayer] : stopped" |
print( "[TodicPlayer] : stopped") |
133 |
url = __backend__ + "&action=playbacktime&subaction=stopped&time=" + str( self.playingPosition ) |
self.reportPlaytime("stopped") |
134 |
open_url_safe(url) |
|
135 |
|
def onPlayBackPaused(self): |
136 |
|
print( "[TodicPlayer] : paused") |
137 |
|
self.reportPlaytime("paused") |
138 |
|
|
139 |
|
def onPlayBackResumed(self): |
140 |
|
print( "[TodicPlayer] : resumed") |
141 |
|
self.reportPlaytime("resumed") |
142 |
|
|
143 |
|
|
144 |
def onPlayBackEnded(self): |
def onPlayBackEnded(self): |
145 |
self.stopped = True |
self.stopped = True |
146 |
print "[TodicPlayer] : ended" |
print( "[TodicPlayer] : ended") |
147 |
url = __backend__ + "&action=playbacktime&subaction=ended&time=" |
self.reportPlaytime("ended") |
|
open_url_safe(url) |
|
148 |
|
|
149 |
def tick(self): |
def tick(self): |
150 |
|
#print "[Todic] Tick: " + str( self.isPlaying() ) |
151 |
if ( self.isPlaying() ): |
if ( self.isPlaying() ): |
152 |
self.playingPosition = self.getTime() |
tmpTime = self.getTime() |
|
now = time() |
|
|
#print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) |
|
|
if ( (now - self.lastReport) > 60.0): |
|
|
self.lastReport = now |
|
|
self.reportPlaytime() |
|
|
|
|
|
|
|
153 |
|
|
154 |
|
#only report time if it has changed in the mean time |
155 |
|
if tmpTime != self.playingPosition: |
156 |
|
self.playingPosition = tmpTime |
157 |
|
now = time() |
158 |
|
#print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) |
159 |
|
if ( (now - self.lastReport) > 60.0): |
160 |
|
self.lastReport = now |
161 |
|
self.reportPlaytime("playing") |
162 |
|
|
163 |
|
def reportPlaytime(self, subaction): |
164 |
|
if (self.playingPosition > 60): |
165 |
|
url = __backend__ + "&action=playbacktime&subaction=" + subaction + "&time=" + str( self.playingPosition ) |
166 |
|
print( "[Todic] reportPlaytime:" + url) |
167 |
|
open_url_safe(url) |
168 |
|
|
|
def reportPlaytime(self): |
|
|
url = __backend__ + "&action=playbacktime&subaction=playing&time=" + str( self.playingPosition ) |
|
|
open_url_safe(url) |
|
|
print "[Todic] reportPlaytime:" + url |
|
|
|
|
169 |
|
|
170 |
|
|
171 |
def getText2(nodelist): |
def getText2(nodelist): |
210 |
try: |
try: |
211 |
return open_url(url) |
return open_url(url) |
212 |
except: |
except: |
213 |
print "[Todic ]Some error during open_url call to ", url |
print( "[Todic] Some error during open_url call to ", url) |
214 |
|
|
215 |
|
|
216 |
|
|
217 |
def rootMenu(): |
def rootMenu(): |
218 |
|
kodi_ver = xbmc.getInfoLabel('System.BuildVersion') |
219 |
|
plugin_ver = __addon__.getAddonInfo('version') |
220 |
|
msgurl = __backend__ + "&action=messages&kodi=" + urllib.quote_plus(kodi_ver) + "&todicplugin=" + urllib.quote_plus(plugin_ver) |
221 |
|
|
222 |
msg = open_url(__backend__ + "&action=messages") |
msg = open_url(msgurl) |
223 |
msg = msg.strip() |
msg = msg.strip() |
224 |
|
|
225 |
if msg != "": |
if msg != "": |
230 |
|
|
231 |
# Adde xtra items to root menu |
# Adde xtra items to root menu |
232 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
233 |
label="Søg film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
label="Søg Film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
234 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
235 |
|
|
236 |
u = sys.argv[0] + "?mode=10&name=" |
u = sys.argv[0] + "?mode=10&name=" |
250 |
|
|
251 |
|
|
252 |
def buildList(url, title, endlist=True): |
def buildList(url, title, endlist=True): |
253 |
print '[TODIC]:' + str(url) |
print( '[Todic]:' + str(url) ) |
254 |
|
|
255 |
link = open_url(url) |
link = open_url(url) |
256 |
doc = parseString(link) |
doc = parseString(link) |
257 |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
258 |
print '[TODIC]' + str(ty) |
print( '[Todic]' + str(ty)) |
259 |
|
|
260 |
if ty == 'clipList': |
if ty == 'clipList': |
261 |
mode = '50' |
mode = '50' |
266 |
|
|
267 |
entries = doc.getElementsByTagName("entry") |
entries = doc.getElementsByTagName("entry") |
268 |
l = len(entries) |
l = len(entries) |
269 |
description = '' |
|
270 |
for entry in entries: |
for entry in entries: |
271 |
name = getText(entry.getElementsByTagName("title")) |
name = getText(entry.getElementsByTagName("title")) |
272 |
url = getText(entry.getElementsByTagName("url")) |
url = getText(entry.getElementsByTagName("url")) |
273 |
thumb = getText(entry.getElementsByTagName("cover")) |
thumb = getText(entry.getElementsByTagName("cover")) |
|
description = getText(entry.getElementsByTagName("description")) |
|
274 |
playcount = getText(entry.getElementsByTagName("playcount")) |
playcount = getText(entry.getElementsByTagName("playcount")) |
|
pos = getText(entry.getElementsByTagName("pos")) |
|
275 |
|
|
276 |
|
|
277 |
if playcount == '': |
if playcount == '': |
281 |
# print "name:" + name |
# print "name:" + name |
282 |
# print "url:" + url |
# print "url:" + url |
283 |
# print "thumb:" + thumb |
# print "thumb:" + thumb |
|
# print "description:" + description |
|
284 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
285 |
label=name, label2='test', iconImage='DefaultFolder.png', thumbnailImage=thumb) |
label=name, label2='test', iconImage='DefaultFolder.png') |
286 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
287 |
|
listitem.addContextMenuItems([('Refresh', 'Container.Refresh')]) |
288 |
|
|
289 |
if mode == '50': |
if mode == '50': |
290 |
infoLabels = {} |
infoLabels = {} |
291 |
infoLabels['title'] = name |
infoLabels['title'] = name |
|
infoLabels['plot'] = description |
|
292 |
infoLabels['playcount'] = playcount |
infoLabels['playcount'] = playcount |
293 |
|
if playcount > 0: |
294 |
|
listitem.setArt( {'thumb': thumb} ) #not pretty - but at least we can show a different icon for unwatched/watched in kodi18 |
295 |
listitem.setInfo('video', infoLabels) |
listitem.setInfo('video', infoLabels) |
296 |
|
listitem.setProperty('IsPlayable', 'true') |
297 |
|
|
298 |
name = name.encode('UTF-8') |
name = name.encode('UTF-8') |
|
description = description.encode('UTF-8') |
|
299 |
|
|
300 |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
301 |
name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) + "&pos=" + pos |
name) + "&url=" + urllib.quote(url) |
302 |
xbmcplugin.addDirectoryItem( |
xbmcplugin.addDirectoryItem( |
303 |
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) |
304 |
|
|
306 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
307 |
|
|
308 |
|
|
309 |
def play_video(url, name, description): |
def play_video(url, name): |
310 |
|
description = "" |
311 |
|
playPosition = 0 |
312 |
|
savedPosition = 0 |
313 |
|
try: |
314 |
|
param1 = parse_parameter_string(url) |
315 |
|
clipkey = param1["clipkey"] |
316 |
|
|
317 |
|
print( "[Todic] ClipKey:" + clipkey) |
318 |
|
detailurl = __backend__ + "&action=clipdetails&clipkey=" + clipkey |
319 |
|
print( "[Todic] detailURL = " + detailurl) |
320 |
|
|
321 |
|
xml = open_url(detailurl) |
322 |
|
|
323 |
|
clipDetailsDoc = parseString(xml) |
324 |
|
savedPosition = int( getText(clipDetailsDoc.getElementsByTagName("position")) ) |
325 |
|
description = getText(clipDetailsDoc.getElementsByTagName("description")) |
326 |
|
except: |
327 |
|
print( "[Todic] Unexpected error:", sys.exc_info()[0] ) |
328 |
|
|
329 |
if (description == None or description == ""): |
if (description == None or description == ""): |
330 |
play_real_video(url, name, 0) |
if (savedPosition > 0): |
331 |
|
dialog = xbmcgui.Dialog() |
332 |
|
#yes / true -afspil fra position |
333 |
|
answer = dialog.yesno(heading='Todic', line1='Afspil fra sidste position', nolabel='Fra start', yeslabel='Fortsæt') |
334 |
|
if (answer == True): |
335 |
|
playPosition = savedPosition |
336 |
|
|
337 |
|
play_real_video(url, name, playPosition) |
338 |
|
|
339 |
else: |
else: |
340 |
d = TodicMovieDialog() |
d = TodicMovieDialog() |
341 |
d.setUrl(url) |
d.setDetailsDoc(clipDetailsDoc) |
342 |
d.setName(name) |
d.setName(name) |
343 |
|
d.setUrl(url) |
344 |
d.setDescription(description) |
d.setDescription(description) |
|
d.setPosition(pos) #tager pos fra global scope |
|
345 |
|
|
346 |
d.doModal() |
d.doModal() |
347 |
|
|
348 |
|
|
349 |
def play_real_video(url, name, position): |
def play_real_video(url, name, position): |
350 |
xml = open_url(url) |
xml = open_url(url) |
351 |
print '[Todic] url: ' + str(url) |
print( '[Todic] url: ' + str(url) ) |
352 |
print '[Todic] xml: ' + xml |
print( '[Todic] xml: ' + xml ) |
353 |
print '[Todic] pos: ' + str(position) |
print( '[Todic] pos: ' + str(position) ) |
354 |
|
|
355 |
doc = parseString(xml) |
doc = parseString(xml) |
356 |
url = getText(doc.getElementsByTagName("url")) |
url = getText(doc.getElementsByTagName("url")) |
357 |
|
|
358 |
subtitleurl = getText(doc.getElementsByTagName("subtitles")) |
subtitleurl = getText(doc.getElementsByTagName("subtitles")) |
|
subtitlesfile = os.path.join(datapath, 'temp.srt') |
|
359 |
|
|
|
# if old srt file exists delete it first |
|
|
if os.path.isfile(subtitlesfile): |
|
|
os.unlink(subtitlesfile) |
|
360 |
|
|
361 |
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' |
|
362 |
|
|
363 |
image = xbmc.getInfoImage('ListItem.Thumb') |
image = xbmc.getInfoImage('ListItem.Thumb') |
364 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
365 |
label=name, iconImage='DefaultVideo.png', thumbnailImage=image) |
label=name, iconImage='DefaultVideo.png', thumbnailImage=image) |
366 |
listitem.setInfo(type="Video", infoLabels={"Title": name}) |
listitem.setInfo(type="Video", infoLabels={"Title": name}) |
|
listitem.setProperty('ResumeTime', '300') |
|
|
listitem.setProperty('TotalTime', '3000') |
|
367 |
|
|
368 |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
listitem.setProperty('StartOffset', str(position) ) |
|
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 |
|
|
|
|
|
|
|
|
|
|
|
if xbmc.Player().isPlaying(): |
|
|
if os.path.isfile(subtitlesfile): |
|
|
player.setSubtitles(subtitlesfile) |
|
|
print 'TODIC started subtitles' |
|
|
else: |
|
|
player.disableSubtitles() |
|
369 |
|
|
370 |
|
if len(subtitleurl) > 0: |
371 |
|
listitem.setSubtitles([subtitleurl]) |
372 |
|
|
373 |
if (position > 0): |
player = TodicPlayer() |
374 |
while (player.getTotalTime() == 0.0): #Vent indtil vi har beregnet hvor langt klippet er |
player.play(str(url), listitem) |
|
xbmc.sleep(250) |
|
|
|
|
|
print "[Todic] totalTime " + str( player.getTotalTime() ) |
|
|
player.seekTime(position) |
|
375 |
|
|
376 |
|
|
377 |
#Holder python kørernde indtil at det bliver bedt om at stoppe |
#Holder python kørernde indtil at det bliver bedt om at stoppe |
388 |
url = __backend__ + "&action=search&search=" + \ |
url = __backend__ + "&action=search&search=" + \ |
389 |
urllib.quote_plus(search) |
urllib.quote_plus(search) |
390 |
|
|
391 |
# print "[TODIC] Search start: " + search |
# print "[Todic] Search start: " + search |
392 |
# print "[TODIC] Search url: " + url |
# print "[Todic] Search url: " + url |
393 |
|
|
394 |
buildList(url, "søgning") |
buildList(url, "søgning") |
395 |
|
|
401 |
url = __backend__ + "&action=searchseries&search=" + \ |
url = __backend__ + "&action=searchseries&search=" + \ |
402 |
urllib.quote_plus(search) |
urllib.quote_plus(search) |
403 |
|
|
404 |
# print "[TODIC] Search start: " + search |
# print "[Todic] Search start: " + search |
405 |
# print "[TODIC] Search url: " + url |
# print "[Todic] Search url: " + url |
406 |
|
|
407 |
buildList(url, "serie søgning") |
buildList(url, "serie søgning") |
408 |
|
|
458 |
url = None |
url = None |
459 |
name = None |
name = None |
460 |
mode = None |
mode = None |
461 |
description = None |
|
|
pos = 0 |
|
462 |
|
|
463 |
#print params |
#print params |
464 |
|
|
474 |
mode = int(params["mode"]) |
mode = int(params["mode"]) |
475 |
except: |
except: |
476 |
pass |
pass |
|
try: |
|
|
description = urllib.unquote_plus(params["description"]) |
|
|
except: |
|
|
pass |
|
|
|
|
477 |
|
|
478 |
|
|
|
try: |
|
|
pos = int(params["pos"]) |
|
|
except: |
|
|
pass |
|
479 |
|
|
480 |
|
|
481 |
try: |
try: |
507 |
|
|
508 |
|
|
509 |
elif mode == 50: |
elif mode == 50: |
510 |
play_video(url, name, description) |
play_video(url, name) |