3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 0.0.21 |
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 |
|
if __entrypoint__ == "alternative": |
31 |
|
__backend__ = "https://alt.todic.dk/xbmc.php?xbmckey=" + __key__ |
32 |
|
|
33 |
|
if __entrypoint__ == "testing": |
34 |
|
__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') |
41 |
datapath = xbmc.translatePath( |
datapath = xbmc.translatePath( |
42 |
'special://profile/addon_data/plugin.video.todic/') |
'special://profile/addon_data/plugin.video.todic/') |
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) |
92 |
#self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width |
#self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width |
93 |
#self.getControl(40).setWidth(int(self.starwidth)) |
#self.getControl(40).setWidth(int(self.starwidth)) |
94 |
|
|
95 |
|
def setDetailsDoc(self, detailsDoc): |
96 |
|
print( "[Todic] MovieDialog setDetailsDoc:") |
97 |
|
self.imdbrating = getText(detailsDoc.getElementsByTagName("imdbrating")) |
98 |
|
self.moviegroups = getText(detailsDoc.getElementsByTagName("moviegroups")) |
99 |
|
self.playlength = getText(detailsDoc.getElementsByTagName("playlength")) |
100 |
|
self.codecdetails = getText(detailsDoc.getElementsByTagName("codecdetails")) |
101 |
|
self.position = int( getText(detailsDoc.getElementsByTagName("position")) ) |
102 |
|
|
103 |
def setUrl(self, url): |
def setUrl(self, url): |
|
print "[Todic] MovieDialog SETURL:" + url |
|
104 |
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 |
|
|
print "[Todic] detailURL = " + detailurl |
|
|
|
|
|
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")) |
|
|
self.position = int( getText(doc.getElementsByTagName("position")) ) |
|
105 |
|
|
106 |
def setName(self, name): |
def setName(self, name): |
107 |
self.name = name |
self.name = name |
114 |
|
|
115 |
def __init__(self, *args, **kwargs): |
def __init__(self, *args, **kwargs): |
116 |
# xbmc.Player.__init__(selv,*args,**kwargs) |
# xbmc.Player.__init__(selv,*args,**kwargs) |
117 |
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) |
xbmc.Player.__init__(self) |
118 |
self.stopped = False |
self.stopped = False |
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 |
|
|
|
# @catchall |
|
124 |
def onPlayBackStarted(self): |
def onPlayBackStarted(self): |
125 |
self.started = True |
self.started = True |
126 |
print "[TodicPlayer] : started" |
print( "[TodicPlayer] : started") |
|
# super.onPlayBackStarted() |
|
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 |
# url = __backend__ + "&action=playbacktime&subaction=stopped&time=" + str( self.playingPosition ) |
|
134 |
# open_url_safe(url) |
def onPlayBackPaused(self): |
135 |
|
print( "[TodicPlayer] : paused") |
136 |
|
self.reportPlaytime("paused") |
137 |
|
|
138 |
|
def onPlayBackResumed(self): |
139 |
|
print( "[TodicPlayer] : resumed") |
140 |
|
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") |
|
# url = __backend__ + "&action=playbacktime&subaction=ended&time=" |
|
|
# open_url_safe(url) |
|
147 |
|
|
148 |
def tick(self): |
def tick(self): |
149 |
|
#print "[Todic] Tick: " + str( self.isPlaying() ) |
150 |
if ( self.isPlaying() ): |
if ( self.isPlaying() ): |
151 |
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("playing") |
|
|
|
|
|
|
|
152 |
|
|
153 |
|
#only report time if it has changed in the mean time |
154 |
|
if tmpTime != self.playingPosition: |
155 |
|
self.playingPosition = tmpTime |
156 |
|
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 |
url = __backend__ + "&action=playbacktime&subaction=" + subaction + "&time=" + str( self.playingPosition ) |
if (self.playingPosition > 60): |
164 |
open_url_safe(url) |
url = __backend__ + "&action=playbacktime&subaction=" + subaction + "&time=" + str( self.playingPosition ) |
165 |
print "[Todic] reportPlaytime:" + url |
print( "[Todic] reportPlaytime:" + url) |
166 |
|
open_url_safe(url) |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
def getText2(nodelist): |
def getText2(nodelist): |
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 |
|
|
226 |
|
|
227 |
# Adde xtra items to root menu |
# Adde xtra items to root menu |
228 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
229 |
label="Søg film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
label="Søg Film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
230 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
231 |
|
|
232 |
u = sys.argv[0] + "?mode=10&name=" |
u = sys.argv[0] + "?mode=10&name=" |
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' |
262 |
|
|
263 |
entries = doc.getElementsByTagName("entry") |
entries = doc.getElementsByTagName("entry") |
264 |
l = len(entries) |
l = len(entries) |
265 |
description = '' |
|
266 |
for entry in entries: |
for entry in entries: |
267 |
name = getText(entry.getElementsByTagName("title")) |
name = getText(entry.getElementsByTagName("title")) |
268 |
url = getText(entry.getElementsByTagName("url")) |
url = getText(entry.getElementsByTagName("url")) |
269 |
thumb = getText(entry.getElementsByTagName("cover")) |
thumb = getText(entry.getElementsByTagName("cover")) |
|
description = getText(entry.getElementsByTagName("description")) |
|
270 |
playcount = getText(entry.getElementsByTagName("playcount")) |
playcount = getText(entry.getElementsByTagName("playcount")) |
271 |
|
|
272 |
|
|
277 |
# print "name:" + name |
# print "name:" + name |
278 |
# print "url:" + url |
# print "url:" + url |
279 |
# print "thumb:" + thumb |
# print "thumb:" + thumb |
|
# print "description:" + description |
|
280 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
281 |
label=name, label2='test', iconImage='DefaultFolder.png', thumbnailImage=thumb) |
label=name, label2='test', iconImage='DefaultFolder.png', thumbnailImage=thumb) |
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 |
|
infoLabels['plot'] = description |
|
288 |
infoLabels['playcount'] = playcount |
infoLabels['playcount'] = playcount |
289 |
listitem.setInfo('video', infoLabels) |
listitem.setInfo('video', infoLabels) |
290 |
|
|
291 |
name = name.encode('UTF-8') |
name = name.encode('UTF-8') |
|
description = description.encode('UTF-8') |
|
292 |
|
|
293 |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
294 |
name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) |
name) + "&url=" + urllib.quote(url) |
295 |
xbmcplugin.addDirectoryItem( |
xbmcplugin.addDirectoryItem( |
296 |
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) |
297 |
|
|
299 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
300 |
|
|
301 |
|
|
302 |
def play_video(url, name, description): |
def play_video(url, name): |
303 |
|
description = "" |
304 |
|
playPosition = 0 |
305 |
|
savedPosition = 0 |
306 |
|
try: |
307 |
|
param1 = parse_parameter_string(url) |
308 |
|
clipkey = param1["clipkey"] |
309 |
|
|
310 |
|
print( "[Todic] ClipKey:" + clipkey) |
311 |
|
detailurl = __backend__ + "&action=clipdetails&clipkey=" + clipkey |
312 |
|
print( "[Todic] detailURL = " + detailurl) |
313 |
|
|
314 |
|
xml = open_url(detailurl) |
315 |
|
|
316 |
|
clipDetailsDoc = parseString(xml) |
317 |
|
savedPosition = int( getText(clipDetailsDoc.getElementsByTagName("position")) ) |
318 |
|
description = getText(clipDetailsDoc.getElementsByTagName("description")) |
319 |
|
except: |
320 |
|
print( "[Todic] Unexpected error:", sys.exc_info()[0] ) |
321 |
|
|
322 |
if (description == None or description == ""): |
if (description == None or description == ""): |
323 |
play_real_video(url, name, 0) |
if (savedPosition > 0): |
324 |
|
dialog = xbmcgui.Dialog() |
325 |
|
#yes / true -afspil fra position |
326 |
|
answer = dialog.yesno(heading='Todic', line1='Afspil fra sidste position', nolabel='Fra start', yeslabel='Fortsæt') |
327 |
|
if (answer == True): |
328 |
|
playPosition = savedPosition |
329 |
|
|
330 |
|
play_real_video(url, name, playPosition) |
331 |
|
|
332 |
else: |
else: |
333 |
d = TodicMovieDialog() |
d = TodicMovieDialog() |
334 |
d.setUrl(url) |
d.setDetailsDoc(clipDetailsDoc) |
335 |
d.setName(name) |
d.setName(name) |
336 |
|
d.setUrl(url) |
337 |
d.setDescription(description) |
d.setDescription(description) |
338 |
|
|
339 |
d.doModal() |
d.doModal() |
341 |
|
|
342 |
def play_real_video(url, name, position): |
def play_real_video(url, name, position): |
343 |
xml = open_url(url) |
xml = open_url(url) |
344 |
print '[Todic] url: ' + str(url) |
print( '[Todic] url: ' + str(url) ) |
345 |
print '[Todic] xml: ' + xml |
print( '[Todic] xml: ' + xml ) |
346 |
print '[Todic] pos: ' + str(position) |
print( '[Todic] pos: ' + str(position) ) |
347 |
|
|
348 |
doc = parseString(xml) |
doc = parseString(xml) |
349 |
url = getText(doc.getElementsByTagName("url")) |
url = getText(doc.getElementsByTagName("url")) |
355 |
if os.path.isfile(subtitlesfile): |
if os.path.isfile(subtitlesfile): |
356 |
os.unlink(subtitlesfile) |
os.unlink(subtitlesfile) |
357 |
|
|
358 |
print '[TODIC] subs: ' + str(subtitleurl) |
print( '[Todic] subs: ' + str(subtitleurl) ) |
359 |
if len(subtitleurl) > 0: |
if len(subtitleurl) > 0: |
360 |
subtitles = open_url(subtitleurl) |
subtitles = open_url(subtitleurl) |
361 |
SaveFile(subtitlesfile, subtitles) |
SaveFile(subtitlesfile, subtitles) |
362 |
print 'TODIC downloaded subtitles' |
print( '[Todic] downloaded subtitles' ) |
363 |
|
|
364 |
image = xbmc.getInfoImage('ListItem.Thumb') |
image = xbmc.getInfoImage('ListItem.Thumb') |
365 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
368 |
listitem.setProperty('ResumeTime', '300') |
listitem.setProperty('ResumeTime', '300') |
369 |
listitem.setProperty('TotalTime', '3000') |
listitem.setProperty('TotalTime', '3000') |
370 |
|
|
371 |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
player = TodicPlayer() |
372 |
player.play(str(url), listitem) |
player.play(str(url), listitem) |
373 |
|
|
374 |
# kan ikke loade subtitles hvis foerend playeren koerer |
# kan ikke loade subtitles hvis foerend playeren koerer |
384 |
if xbmc.Player().isPlaying(): |
if xbmc.Player().isPlaying(): |
385 |
if os.path.isfile(subtitlesfile): |
if os.path.isfile(subtitlesfile): |
386 |
player.setSubtitles(subtitlesfile) |
player.setSubtitles(subtitlesfile) |
387 |
print 'TODIC started subtitles' |
print( '[Todic] started subtitles') |
388 |
else: |
else: |
389 |
player.disableSubtitles() |
player.showSubtitles(False) |
390 |
|
|
391 |
|
|
392 |
if (position > 0): |
if (position > 0): |
393 |
while (player.getTotalTime() == 0.0): #Vent indtil vi har beregnet hvor langt klippet er |
while (player.getTotalTime() == 0.0): #Vent indtil vi har beregnet hvor langt klippet er |
394 |
xbmc.sleep(250) |
xbmc.sleep(250) |
395 |
|
|
396 |
print "[Todic] totalTime " + str( player.getTotalTime() ) |
print( "[Todic] totalTime " + str( player.getTotalTime() )) |
397 |
player.seekTime(position) |
player.seekTime(position) |
398 |
|
|
399 |
|
|
411 |
url = __backend__ + "&action=search&search=" + \ |
url = __backend__ + "&action=search&search=" + \ |
412 |
urllib.quote_plus(search) |
urllib.quote_plus(search) |
413 |
|
|
414 |
# print "[TODIC] Search start: " + search |
# print "[Todic] Search start: " + search |
415 |
# print "[TODIC] Search url: " + url |
# print "[Todic] Search url: " + url |
416 |
|
|
417 |
buildList(url, "søgning") |
buildList(url, "søgning") |
418 |
|
|
424 |
url = __backend__ + "&action=searchseries&search=" + \ |
url = __backend__ + "&action=searchseries&search=" + \ |
425 |
urllib.quote_plus(search) |
urllib.quote_plus(search) |
426 |
|
|
427 |
# print "[TODIC] Search start: " + search |
# print "[Todic] Search start: " + search |
428 |
# print "[TODIC] Search url: " + url |
# print "[Todic] Search url: " + url |
429 |
|
|
430 |
buildList(url, "serie søgning") |
buildList(url, "serie søgning") |
431 |
|
|
481 |
url = None |
url = None |
482 |
name = None |
name = None |
483 |
mode = None |
mode = None |
|
description = None |
|
484 |
|
|
485 |
|
|
486 |
#print params |
#print params |
497 |
mode = int(params["mode"]) |
mode = int(params["mode"]) |
498 |
except: |
except: |
499 |
pass |
pass |
|
try: |
|
|
description = urllib.unquote_plus(params["description"]) |
|
|
except: |
|
|
pass |
|
500 |
|
|
501 |
|
|
502 |
|
|
530 |
|
|
531 |
|
|
532 |
elif mode == 50: |
elif mode == 50: |
533 |
play_video(url, name, description) |
play_video(url, name) |