3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 0.0.20 |
Version 1.7 |
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 |
|
|
37 |
|
|
38 |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
39 |
datapath = xbmc.translatePath( |
datapath = xbmc.translatePath( |
40 |
'special://profile/addon_data/plugin.video.todic/') |
'special://profile/addon_data/plugin.video.todic/') |
70 |
|
|
71 |
def onInit(self): |
def onInit(self): |
72 |
|
|
73 |
print "[Todic] MovieDialog ONINIT" |
print "[Todic] MovieDialog onInit" |
74 |
self.getControl(1).setLabel(self.name) |
self.getControl(1).setLabel(self.name) |
75 |
self.getControl(2).setLabel(self.moviegroups) |
self.getControl(2).setLabel(self.moviegroups) |
76 |
self.getControl(3).setLabel(self.description) |
self.getControl(3).setLabel(self.description) |
90 |
#self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width |
#self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width |
91 |
#self.getControl(40).setWidth(int(self.starwidth)) |
#self.getControl(40).setWidth(int(self.starwidth)) |
92 |
|
|
93 |
|
def setDetailsDoc(self, detailsDoc): |
94 |
|
print "[Todic] MovieDialog setDetailsDoc:" |
95 |
|
self.imdbrating = getText(detailsDoc.getElementsByTagName("imdbrating")) |
96 |
|
self.moviegroups = getText(detailsDoc.getElementsByTagName("moviegroups")) |
97 |
|
self.playlength = getText(detailsDoc.getElementsByTagName("playlength")) |
98 |
|
self.codecdetails = getText(detailsDoc.getElementsByTagName("codecdetails")) |
99 |
|
self.position = int( getText(detailsDoc.getElementsByTagName("position")) ) |
100 |
|
|
101 |
def setUrl(self, url): |
def setUrl(self, url): |
|
print "[Todic] MovieDialog SETURL:" + url |
|
102 |
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")) |
|
103 |
|
|
104 |
def setName(self, name): |
def setName(self, name): |
105 |
self.name = name |
self.name = name |
112 |
|
|
113 |
def __init__(self, *args, **kwargs): |
def __init__(self, *args, **kwargs): |
114 |
# xbmc.Player.__init__(selv,*args,**kwargs) |
# xbmc.Player.__init__(selv,*args,**kwargs) |
115 |
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) |
xbmc.Player.__init__(self) |
116 |
self.stopped = False |
self.stopped = False |
117 |
self.started = False |
self.started = False |
118 |
self.playingPosition = 0.0 |
self.playingPosition = 0.0 |
119 |
self.lastReport = 0 |
self.lastReport = 0 |
120 |
print "[TodicPlayer] init" |
print "[TodicPlayer] init" |
121 |
|
|
|
# @catchall |
|
122 |
def onPlayBackStarted(self): |
def onPlayBackStarted(self): |
123 |
self.started = True |
self.started = True |
124 |
print "[TodicPlayer] : started" |
print "[TodicPlayer] : started" |
|
# super.onPlayBackStarted() |
|
125 |
|
|
126 |
#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() |
127 |
def onPlayBackStopped(self): |
def onPlayBackStopped(self): |
128 |
self.stopped = True |
self.stopped = True |
129 |
print "[TodicPlayer] : stopped" |
print "[TodicPlayer] : stopped" |
130 |
url = __backend__ + "&action=playbacktime&subaction=stopped&time=" + str( self.playingPosition ) |
self.reportPlaytime("stopped") |
131 |
open_url_safe(url) |
|
132 |
|
def onPlayBackPaused(self): |
133 |
|
print "[TodicPlayer] : paused" |
134 |
|
self.reportPlaytime("paused") |
135 |
|
|
136 |
|
def onPlayBackResumed(self): |
137 |
|
print "[TodicPlayer] : resumed" |
138 |
|
self.reportPlaytime("resumed") |
139 |
|
|
140 |
|
|
141 |
def onPlayBackEnded(self): |
def onPlayBackEnded(self): |
142 |
self.stopped = True |
self.stopped = True |
143 |
print "[TodicPlayer] : ended" |
print "[TodicPlayer] : ended" |
144 |
url = __backend__ + "&action=playbacktime&subaction=ended&time=" |
self.reportPlaytime("ended") |
|
open_url_safe(url) |
|
145 |
|
|
146 |
def tick(self): |
def tick(self): |
147 |
|
#print "[Todic] Tick: " + str( self.isPlaying() ) |
148 |
if ( self.isPlaying() ): |
if ( self.isPlaying() ): |
149 |
self.playingPosition = self.getTime() |
self.playingPosition = self.getTime() |
150 |
now = time() |
now = time() |
151 |
#print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) |
#print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) |
152 |
if ( (now - self.lastReport) > 60.0): |
if ( (now - self.lastReport) > 60.0): |
153 |
self.lastReport = now |
self.lastReport = now |
154 |
self.reportPlaytime() |
self.reportPlaytime("playing") |
|
|
|
|
|
|
155 |
|
|
156 |
|
def reportPlaytime(self, subaction): |
157 |
|
if (self.playingPosition > 60): |
158 |
|
url = __backend__ + "&action=playbacktime&subaction=" + subaction + "&time=" + str( self.playingPosition ) |
159 |
|
print "[Todic] reportPlaytime:" + url |
160 |
|
open_url_safe(url) |
161 |
|
|
|
def reportPlaytime(self): |
|
|
url = __backend__ + "&action=playbacktime&subaction=playing&time=" + str( self.playingPosition ) |
|
|
open_url_safe(url) |
|
|
print "[Todic] reportPlaytime:" + url |
|
|
|
|
162 |
|
|
163 |
|
|
164 |
def getText2(nodelist): |
def getText2(nodelist): |
203 |
try: |
try: |
204 |
return open_url(url) |
return open_url(url) |
205 |
except: |
except: |
206 |
print "[Todic ]Some error during open_url call to ", url |
print "[Todic] Some error during open_url call to ", url |
207 |
|
|
208 |
|
|
209 |
|
|
220 |
|
|
221 |
# Adde xtra items to root menu |
# Adde xtra items to root menu |
222 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
223 |
label="Søg film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
label="Søg Film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
224 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
225 |
|
|
226 |
u = sys.argv[0] + "?mode=10&name=" |
u = sys.argv[0] + "?mode=10&name=" |
240 |
|
|
241 |
|
|
242 |
def buildList(url, title, endlist=True): |
def buildList(url, title, endlist=True): |
243 |
print '[TODIC]:' + str(url) |
print '[Todic]:' + str(url) |
244 |
|
|
245 |
link = open_url(url) |
link = open_url(url) |
246 |
doc = parseString(link) |
doc = parseString(link) |
247 |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
248 |
print '[TODIC]' + str(ty) |
print '[Todic]' + str(ty) |
249 |
|
|
250 |
if ty == 'clipList': |
if ty == 'clipList': |
251 |
mode = '50' |
mode = '50' |
256 |
|
|
257 |
entries = doc.getElementsByTagName("entry") |
entries = doc.getElementsByTagName("entry") |
258 |
l = len(entries) |
l = len(entries) |
259 |
description = '' |
|
260 |
for entry in entries: |
for entry in entries: |
261 |
name = getText(entry.getElementsByTagName("title")) |
name = getText(entry.getElementsByTagName("title")) |
262 |
url = getText(entry.getElementsByTagName("url")) |
url = getText(entry.getElementsByTagName("url")) |
263 |
thumb = getText(entry.getElementsByTagName("cover")) |
thumb = getText(entry.getElementsByTagName("cover")) |
|
description = getText(entry.getElementsByTagName("description")) |
|
264 |
playcount = getText(entry.getElementsByTagName("playcount")) |
playcount = getText(entry.getElementsByTagName("playcount")) |
|
pos = getText(entry.getElementsByTagName("pos")) |
|
265 |
|
|
266 |
|
|
267 |
if playcount == '': |
if playcount == '': |
271 |
# print "name:" + name |
# print "name:" + name |
272 |
# print "url:" + url |
# print "url:" + url |
273 |
# print "thumb:" + thumb |
# print "thumb:" + thumb |
|
# print "description:" + description |
|
274 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
275 |
label=name, label2='test', iconImage='DefaultFolder.png', thumbnailImage=thumb) |
label=name, label2='test', iconImage='DefaultFolder.png', thumbnailImage=thumb) |
276 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
277 |
if mode == '50': |
if mode == '50': |
278 |
infoLabels = {} |
infoLabels = {} |
279 |
infoLabels['title'] = name |
infoLabels['title'] = name |
|
infoLabels['plot'] = description |
|
280 |
infoLabels['playcount'] = playcount |
infoLabels['playcount'] = playcount |
281 |
listitem.setInfo('video', infoLabels) |
listitem.setInfo('video', infoLabels) |
282 |
|
|
283 |
name = name.encode('UTF-8') |
name = name.encode('UTF-8') |
|
description = description.encode('UTF-8') |
|
284 |
|
|
285 |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
286 |
name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) + "&pos=" + pos |
name) + "&url=" + urllib.quote(url) |
287 |
xbmcplugin.addDirectoryItem( |
xbmcplugin.addDirectoryItem( |
288 |
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) |
289 |
|
|
291 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
292 |
|
|
293 |
|
|
294 |
def play_video(url, name, description): |
def play_video(url, name): |
295 |
|
description = "" |
296 |
|
playPosition = 0 |
297 |
|
savedPosition = 0 |
298 |
|
try: |
299 |
|
param1 = parse_parameter_string(url) |
300 |
|
clipkey = param1["clipkey"] |
301 |
|
|
302 |
|
print "[Todic] ClipKey:" + clipkey |
303 |
|
detailurl = __backend__ + "&action=clipdetails&clipkey=" + clipkey |
304 |
|
print "[Todic] detailURL = " + detailurl |
305 |
|
|
306 |
|
xml = open_url(detailurl) |
307 |
|
|
308 |
|
clipDetailsDoc = parseString(xml) |
309 |
|
savedPosition = int( getText(clipDetailsDoc.getElementsByTagName("position")) ) |
310 |
|
description = getText(clipDetailsDoc.getElementsByTagName("description")) |
311 |
|
except: |
312 |
|
print "[Todic] Unexpected error:", sys.exc_info()[0] |
313 |
|
|
314 |
if (description == None or description == ""): |
if (description == None or description == ""): |
315 |
play_real_video(url, name, 0) |
if (savedPosition > 0): |
316 |
|
dialog = xbmcgui.Dialog() |
317 |
|
#yes / true -afspil fra position |
318 |
|
answer = dialog.yesno(heading='Todic', line1='Afspil fra sidste position', nolabel='Fra start', yeslabel='Fortsæt') |
319 |
|
if (answer == True): |
320 |
|
playPosition = savedPosition |
321 |
|
|
322 |
|
play_real_video(url, name, playPosition) |
323 |
|
|
324 |
else: |
else: |
325 |
d = TodicMovieDialog() |
d = TodicMovieDialog() |
326 |
d.setUrl(url) |
d.setDetailsDoc(clipDetailsDoc) |
327 |
d.setName(name) |
d.setName(name) |
328 |
|
d.setUrl(url) |
329 |
d.setDescription(description) |
d.setDescription(description) |
|
d.setPosition(pos) #tager pos fra global scope |
|
330 |
|
|
331 |
d.doModal() |
d.doModal() |
332 |
|
|
347 |
if os.path.isfile(subtitlesfile): |
if os.path.isfile(subtitlesfile): |
348 |
os.unlink(subtitlesfile) |
os.unlink(subtitlesfile) |
349 |
|
|
350 |
print '[TODIC] subs: ' + str(subtitleurl) |
print '[Todic] subs: ' + str(subtitleurl) |
351 |
if len(subtitleurl) > 0: |
if len(subtitleurl) > 0: |
352 |
subtitles = open_url(subtitleurl) |
subtitles = open_url(subtitleurl) |
353 |
SaveFile(subtitlesfile, subtitles) |
SaveFile(subtitlesfile, subtitles) |
354 |
print 'TODIC downloaded subtitles' |
print '[Todic] downloaded subtitles' |
355 |
|
|
356 |
image = xbmc.getInfoImage('ListItem.Thumb') |
image = xbmc.getInfoImage('ListItem.Thumb') |
357 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
360 |
listitem.setProperty('ResumeTime', '300') |
listitem.setProperty('ResumeTime', '300') |
361 |
listitem.setProperty('TotalTime', '3000') |
listitem.setProperty('TotalTime', '3000') |
362 |
|
|
363 |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
player = TodicPlayer() |
364 |
player.play(str(url), listitem) |
player.play(str(url), listitem) |
365 |
|
|
366 |
# kan ikke loade subtitles hvis foerend playeren koerer |
# kan ikke loade subtitles hvis foerend playeren koerer |
376 |
if xbmc.Player().isPlaying(): |
if xbmc.Player().isPlaying(): |
377 |
if os.path.isfile(subtitlesfile): |
if os.path.isfile(subtitlesfile): |
378 |
player.setSubtitles(subtitlesfile) |
player.setSubtitles(subtitlesfile) |
379 |
print 'TODIC started subtitles' |
print '[Todic] started subtitles' |
380 |
else: |
else: |
381 |
player.disableSubtitles() |
player.showSubtitles(False) |
382 |
|
|
383 |
|
|
384 |
if (position > 0): |
if (position > 0): |
403 |
url = __backend__ + "&action=search&search=" + \ |
url = __backend__ + "&action=search&search=" + \ |
404 |
urllib.quote_plus(search) |
urllib.quote_plus(search) |
405 |
|
|
406 |
# print "[TODIC] Search start: " + search |
# print "[Todic] Search start: " + search |
407 |
# print "[TODIC] Search url: " + url |
# print "[Todic] Search url: " + url |
408 |
|
|
409 |
buildList(url, "søgning") |
buildList(url, "søgning") |
410 |
|
|
416 |
url = __backend__ + "&action=searchseries&search=" + \ |
url = __backend__ + "&action=searchseries&search=" + \ |
417 |
urllib.quote_plus(search) |
urllib.quote_plus(search) |
418 |
|
|
419 |
# print "[TODIC] Search start: " + search |
# print "[Todic] Search start: " + search |
420 |
# print "[TODIC] Search url: " + url |
# print "[Todic] Search url: " + url |
421 |
|
|
422 |
buildList(url, "serie søgning") |
buildList(url, "serie søgning") |
423 |
|
|
473 |
url = None |
url = None |
474 |
name = None |
name = None |
475 |
mode = None |
mode = None |
476 |
description = None |
|
|
pos = 0 |
|
477 |
|
|
478 |
#print params |
#print params |
479 |
|
|
489 |
mode = int(params["mode"]) |
mode = int(params["mode"]) |
490 |
except: |
except: |
491 |
pass |
pass |
|
try: |
|
|
description = urllib.unquote_plus(params["description"]) |
|
|
except: |
|
|
pass |
|
492 |
|
|
493 |
|
|
494 |
|
|
|
try: |
|
|
pos = int(params["pos"]) |
|
|
except: |
|
|
pass |
|
|
|
|
495 |
|
|
496 |
try: |
try: |
497 |
open_url("http://todic.dk") |
open_url("http://todic.dk") |
522 |
|
|
523 |
|
|
524 |
elif mode == 50: |
elif mode == 50: |
525 |
play_video(url, name, description) |
play_video(url, name) |