3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 1.7.1 |
Version 1.9.4 |
7 |
''' |
''' |
8 |
|
|
9 |
import sys |
import sys |
13 |
import xbmc |
import xbmc |
14 |
import xbmcaddon |
import xbmcaddon |
15 |
import xbmcgui |
import xbmcgui |
16 |
|
import xbmcvfs |
17 |
import xbmcplugin |
import xbmcplugin |
18 |
import urllib |
import urllib |
19 |
import urllib2 |
import urllib.request |
20 |
|
|
21 |
|
import platform |
22 |
|
|
23 |
# import pprint |
# import pprint |
24 |
|
|
30 |
__entrypoint__ = __addon__.getSetting('entrypoint').lower() |
__entrypoint__ = __addon__.getSetting('entrypoint').lower() |
31 |
__backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__ |
__backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__ |
32 |
|
|
33 |
|
|
34 |
if __entrypoint__ == "alternative": |
if __entrypoint__ == "alternative": |
35 |
__backend__ = "https://alt.todic.dk/xbmc.php?xbmckey=" + __key__ |
__backend__ = "https://alt.todic.dk/xbmc.php?xbmckey=" + __key__ |
36 |
|
|
37 |
if __entrypoint__ == "testing": |
if __entrypoint__ == "testing": |
38 |
__backend__ = "https://todic.dk/xbmc-beta.php?xbmckey=" + __key__ |
__backend__ = "https://todic.dk/xbmc-beta.php?xbmckey=" + __key__ |
|
|
|
|
print "[Todic] entrypoint: " + __entrypoint__ |
|
|
print "[Todic] backend: " + __backend__ |
|
39 |
|
|
40 |
|
print( "[Todic] entrypoint: " + __entrypoint__ ) |
41 |
|
print( "[Todic] backend: " + __backend__ ) |
42 |
|
print( "[Todic] version: " + __addon__.getAddonInfo('version') ) |
43 |
|
|
44 |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
45 |
datapath = xbmc.translatePath( |
datapath = xbmcvfs.translatePath( |
46 |
'special://profile/addon_data/plugin.video.todic/') |
'special://profile/addon_data/plugin.video.todic/') |
47 |
|
|
48 |
ADDON_PATH = __addon__.getAddonInfo('path') |
ADDON_PATH = __addon__.getAddonInfo('path') |
61 |
self.position = 0 |
self.position = 0 |
62 |
|
|
63 |
def onClick(self, controlId): |
def onClick(self, controlId): |
64 |
print "[Todic] MovieDialog OnClick: " + str(controlId) |
print( "[Todic] MovieDialog OnClick: " + str(controlId) ) |
65 |
|
|
66 |
if (controlId == 50): |
if (controlId == 50): |
67 |
self.close() |
self.close() |
76 |
|
|
77 |
def onInit(self): |
def onInit(self): |
78 |
|
|
79 |
print "[Todic] MovieDialog onInit" |
print( "[Todic] MovieDialog onInit" ) |
80 |
self.getControl(1).setLabel(self.name) |
self.getControl(1).setLabel(self.name) |
81 |
self.getControl(2).setLabel(self.moviegroups) |
self.getControl(2).setLabel(self.moviegroups) |
82 |
self.getControl(3).setLabel(self.description) |
self.getControl(3).setLabel(self.description) |
97 |
#self.getControl(40).setWidth(int(self.starwidth)) |
#self.getControl(40).setWidth(int(self.starwidth)) |
98 |
|
|
99 |
def setDetailsDoc(self, detailsDoc): |
def setDetailsDoc(self, detailsDoc): |
100 |
print "[Todic] MovieDialog setDetailsDoc:" |
print( "[Todic] MovieDialog setDetailsDoc:") |
101 |
self.imdbrating = getText(detailsDoc.getElementsByTagName("imdbrating")) |
self.imdbrating = getText(detailsDoc.getElementsByTagName("imdbrating")) |
102 |
self.moviegroups = getText(detailsDoc.getElementsByTagName("moviegroups")) |
self.moviegroups = getText(detailsDoc.getElementsByTagName("moviegroups")) |
103 |
self.playlength = getText(detailsDoc.getElementsByTagName("playlength")) |
self.playlength = getText(detailsDoc.getElementsByTagName("playlength")) |
123 |
self.started = False |
self.started = False |
124 |
self.playingPosition = 0.0 |
self.playingPosition = 0.0 |
125 |
self.lastReport = 0 |
self.lastReport = 0 |
126 |
print "[TodicPlayer] init" |
print( "[TodicPlayer] init") |
127 |
|
|
128 |
def onPlayBackStarted(self): |
def onPlayBackStarted(self): |
129 |
self.started = True |
self.started = True |
130 |
print "[TodicPlayer] : started" |
print( "[TodicPlayer] : started") |
131 |
|
|
132 |
#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() |
133 |
def onPlayBackStopped(self): |
def onPlayBackStopped(self): |
134 |
self.stopped = True |
self.stopped = True |
135 |
print "[TodicPlayer] : stopped" |
print( "[TodicPlayer] : stopped") |
136 |
self.reportPlaytime("stopped") |
self.reportPlaytime("stopped") |
137 |
|
|
138 |
def onPlayBackPaused(self): |
def onPlayBackPaused(self): |
139 |
print "[TodicPlayer] : paused" |
print( "[TodicPlayer] : paused") |
140 |
self.reportPlaytime("paused") |
self.reportPlaytime("paused") |
141 |
|
|
142 |
def onPlayBackResumed(self): |
def onPlayBackResumed(self): |
143 |
print "[TodicPlayer] : resumed" |
print( "[TodicPlayer] : resumed") |
144 |
self.reportPlaytime("resumed") |
self.reportPlaytime("resumed") |
145 |
|
|
146 |
|
|
147 |
def onPlayBackEnded(self): |
def onPlayBackEnded(self): |
148 |
self.stopped = True |
self.stopped = True |
149 |
print "[TodicPlayer] : ended" |
print( "[TodicPlayer] : ended") |
150 |
self.reportPlaytime("ended") |
self.reportPlaytime("ended") |
151 |
|
|
152 |
def tick(self): |
def tick(self): |
153 |
#print "[Todic] Tick: " + str( self.isPlaying() ) |
#print( "[Todic] Tick: " + str( self.isPlaying() ) ) |
154 |
if ( self.isPlaying() ): |
if ( self.isPlaying() ): |
155 |
tmpTime = self.getTime(): |
tmpTime = self.getTime() |
156 |
|
|
157 |
#only report time if it has changed in the mean time |
#only report time if it has changed in the mean time |
158 |
if tmpTime != self.playingPosition: |
if tmpTime != self.playingPosition: |
159 |
self.playingPosition = tmpTime |
self.playingPosition = tmpTime |
160 |
now = time() |
now = time() |
161 |
#print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) |
#print( "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) ) |
162 |
if ( (now - self.lastReport) > 60.0): |
if ( (now - self.lastReport) > 60.0): |
163 |
self.lastReport = now |
self.lastReport = now |
164 |
self.reportPlaytime("playing") |
self.reportPlaytime("playing") |
166 |
def reportPlaytime(self, subaction): |
def reportPlaytime(self, subaction): |
167 |
if (self.playingPosition > 60): |
if (self.playingPosition > 60): |
168 |
url = __backend__ + "&action=playbacktime&subaction=" + subaction + "&time=" + str( self.playingPosition ) |
url = __backend__ + "&action=playbacktime&subaction=" + subaction + "&time=" + str( self.playingPosition ) |
169 |
print "[Todic] reportPlaytime:" + url |
print( "[Todic] reportPlaytime:" + url) |
170 |
open_url_safe(url) |
open_url_safe(url) |
171 |
|
|
172 |
|
|
200 |
|
|
201 |
|
|
202 |
def open_url(url): |
def open_url(url): |
203 |
req = urllib2.Request(url) |
kodi_ver = xbmc.getInfoLabel('System.BuildVersion') |
204 |
content = urllib2.urlopen(req) |
reqobj = urllib.request.Request( |
205 |
data = content.read() |
url, |
206 |
content.close() |
data=None, |
207 |
return data |
headers={ |
208 |
|
'User-Agent': 'TodicKodi:' + str(__addon__.getAddonInfo('version')) + " Kodi:" + str(kodi_ver) + " Platform:" + str(platform.system()) + " " + str(platform.release()) |
209 |
|
} |
210 |
|
) |
211 |
|
|
212 |
|
with urllib.request.urlopen(reqobj) as req: |
213 |
|
#data = response.read() |
214 |
|
#return data |
215 |
|
charset=req.info().get_content_charset() |
216 |
|
content=req.read().decode(charset) |
217 |
|
return content |
218 |
|
|
219 |
|
|
220 |
# wraps open url in a catch-all exception handler |
# wraps open url in a catch-all exception handler |
223 |
try: |
try: |
224 |
return open_url(url) |
return open_url(url) |
225 |
except: |
except: |
226 |
print "[Todic] Some error during open_url call to ", url |
print( "[Todic] Some error during open_url call to ", url) |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
def rootMenu(): |
def rootMenu(): |
231 |
|
kodi_ver = xbmc.getInfoLabel('System.BuildVersion') |
232 |
|
plugin_ver = __addon__.getAddonInfo('version') |
233 |
|
msgurl = __backend__ + "&action=messages&kodi=" + urllib.parse.quote(kodi_ver) + "&todicplugin=" + urllib.parse.quote(plugin_ver) |
234 |
|
|
235 |
msg = open_url(__backend__ + "&action=messages") |
msg = open_url(msgurl) |
236 |
msg = msg.strip() |
msg = msg.strip() |
237 |
|
|
238 |
if msg != "": |
if msg != "": |
239 |
|
print("[Todic] rootMenu Dialog =" + str(msg)) |
240 |
dialog = xbmcgui.Dialog() |
dialog = xbmcgui.Dialog() |
241 |
dialog.ok('XBMC Todic', msg) |
dialog.ok('XBMC Todic', msg) |
242 |
|
|
243 |
buildList(__backend__, "", False) # call default list |
buildList(__backend__, "", False) # call default list |
244 |
|
|
245 |
# Adde xtra items to root menu |
# Adde xtra items to root menu |
246 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem(label="Søg Film ...") |
247 |
label="Søg Film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
listitem.setArt( { 'icon':'DefaultFolder.png', 'thumb':'DefaultFolder.png'} ) |
248 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
249 |
|
|
250 |
u = sys.argv[0] + "?mode=10&name=" |
u = sys.argv[0] + "?mode=10&name=" |
252 |
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
253 |
|
|
254 |
# add search series |
# add search series |
255 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem(label="Søg Serier ...") |
256 |
label="Søg Serier ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png') |
listitem.setArt( { 'icon':'DefaultFolder.png', 'thumb':'DefaultFolder.png'} ) |
257 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
258 |
|
|
259 |
u = sys.argv[0] + "?mode=11&name=" |
u = sys.argv[0] + "?mode=11&name=" |
264 |
|
|
265 |
|
|
266 |
def buildList(url, title, endlist=True): |
def buildList(url, title, endlist=True): |
267 |
print '[Todic]:' + str(url) |
print( '[Todic::buildList]:' + str(url) ) |
268 |
|
|
269 |
link = open_url(url) |
link = open_url(url) |
270 |
doc = parseString(link) |
doc = parseString(link) |
271 |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
ty = doc.getElementsByTagName("meta")[0].getAttribute("type") |
272 |
print '[Todic]' + str(ty) |
print( '[Todic]' + str(ty)) |
273 |
|
|
274 |
if ty == 'clipList': |
if ty == 'clipList': |
275 |
mode = '50' |
mode = '50' |
294 |
|
|
295 |
# print "name:" + name |
# print "name:" + name |
296 |
# print "url:" + url |
# print "url:" + url |
297 |
# print "thumb:" + thumb |
# print "thumb:" + thumbi |
298 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem(label=name, label2='test') |
299 |
label=name, label2='test', iconImage='DefaultFolder.png', thumbnailImage=thumb) |
listitem.setArt( {'icon': 'DefaultFolder.png'} ) |
300 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
301 |
|
listitem.addContextMenuItems([('Refresh', 'Container.Refresh')]) |
302 |
|
listitem.setArt( {'thumb': thumb} ) |
303 |
|
|
304 |
if mode == '50': |
if mode == '50': |
305 |
infoLabels = {} |
infoLabels = {} |
306 |
infoLabels['title'] = name |
infoLabels['title'] = name |
307 |
infoLabels['playcount'] = playcount |
infoLabels['playcount'] = playcount |
308 |
|
# if playcount > 0: |
309 |
|
# listitem.setArt( {'thumb': thumb} ) #not pretty - but at least we can show a different icon for unwatched/watched in kodi18 |
310 |
listitem.setInfo('video', infoLabels) |
listitem.setInfo('video', infoLabels) |
311 |
|
|
312 |
name = name.encode('UTF-8') |
name = name.encode('UTF-8') |
313 |
|
|
314 |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
u = sys.argv[0] + "?mode=" + urllib.parse.quote(mode) + "&name=" + urllib.parse.quote(name) + "&url=" + urllib.parse.quote(url) |
|
name) + "&url=" + urllib.quote(url) |
|
315 |
xbmcplugin.addDirectoryItem( |
xbmcplugin.addDirectoryItem( |
316 |
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) |
317 |
|
|
327 |
param1 = parse_parameter_string(url) |
param1 = parse_parameter_string(url) |
328 |
clipkey = param1["clipkey"] |
clipkey = param1["clipkey"] |
329 |
|
|
330 |
print "[Todic] ClipKey:" + clipkey |
print( "[Todic] ClipKey:" + clipkey) |
331 |
detailurl = __backend__ + "&action=clipdetails&clipkey=" + clipkey |
detailurl = __backend__ + "&action=clipdetails&clipkey=" + clipkey |
332 |
print "[Todic] detailURL = " + detailurl |
print( "[Todic] detailURL = " + detailurl) |
333 |
|
|
334 |
xml = open_url(detailurl) |
xml = open_url(detailurl) |
335 |
|
|
337 |
savedPosition = int( getText(clipDetailsDoc.getElementsByTagName("position")) ) |
savedPosition = int( getText(clipDetailsDoc.getElementsByTagName("position")) ) |
338 |
description = getText(clipDetailsDoc.getElementsByTagName("description")) |
description = getText(clipDetailsDoc.getElementsByTagName("description")) |
339 |
except: |
except: |
340 |
print "[Todic] Unexpected error:", sys.exc_info()[0] |
print( "[Todic] Unexpected error:", sys.exc_info()[0] ) |
341 |
|
|
342 |
if (description == None or description == ""): |
if (description == None or description == ""): |
343 |
if (savedPosition > 0): |
if (savedPosition > 0): |
344 |
dialog = xbmcgui.Dialog() |
dialog = xbmcgui.Dialog() |
345 |
#yes / true -afspil fra position |
#yes / true -afspil fra position |
346 |
answer = dialog.yesno(heading='Todic', line1='Afspil fra sidste position', nolabel='Fra start', yeslabel='Fortsæt') |
answer = dialog.yesno(heading='Todic', message='Afspil fra sidste position', nolabel='Fra start', yeslabel='Fortsæt') |
347 |
if (answer == True): |
if (answer == True): |
348 |
playPosition = savedPosition |
playPosition = savedPosition |
349 |
|
|
361 |
|
|
362 |
def play_real_video(url, name, position): |
def play_real_video(url, name, position): |
363 |
xml = open_url(url) |
xml = open_url(url) |
364 |
print '[Todic] url: ' + str(url) |
print( '[Todic] url: ' + str(url) ) |
365 |
print '[Todic] xml: ' + xml |
print( '[Todic] xml: ' + str(xml) ) |
366 |
print '[Todic] pos: ' + str(position) |
print( '[Todic] pos: ' + str(position) ) |
367 |
|
|
368 |
doc = parseString(xml) |
doc = parseString(xml) |
369 |
url = getText(doc.getElementsByTagName("url")) |
url = getText(doc.getElementsByTagName("url")) |
370 |
|
|
371 |
subtitleurl = getText(doc.getElementsByTagName("subtitles")) |
subtitleurl = getText(doc.getElementsByTagName("subtitles")) |
|
subtitlesfile = os.path.join(datapath, 'temp.srt') |
|
372 |
|
|
|
# if old srt file exists delete it first |
|
|
if os.path.isfile(subtitlesfile): |
|
|
os.unlink(subtitlesfile) |
|
373 |
|
|
374 |
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' |
|
375 |
|
|
376 |
image = xbmc.getInfoImage('ListItem.Thumb') |
image = xbmc.getInfoImage('ListItem.Thumb') |
377 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem(label=name) |
378 |
label=name, iconImage='DefaultVideo.png', thumbnailImage=image) |
listitem.setArt( {'icon': 'DefaultVideo.png', 'thumb':image} ) |
379 |
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 |
|
380 |
|
|
381 |
|
listitem.setProperty('StartOffset', str(position) ) |
382 |
|
|
383 |
|
if len(subtitleurl) > 0: |
384 |
|
listitem.setSubtitles([subtitleurl]) |
385 |
|
|
386 |
if xbmc.Player().isPlaying(): |
player = TodicPlayer() |
387 |
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) |
|
388 |
|
|
389 |
|
|
390 |
#Holder python kørernde indtil at det bliver bedt om at stoppe |
#Holder python kørernde indtil at det bliver bedt om at stoppe |
391 |
while (not xbmc.abortRequested): |
kodiMonitor = xbmc.Monitor() |
392 |
|
|
393 |
|
|
394 |
|
while (not kodiMonitor.abortRequested()): |
395 |
player.tick() |
player.tick() |
396 |
xbmc.sleep(500) |
kodiMonitor.waitForAbort( 1 ) |
397 |
|
|
398 |
|
|
399 |
|
|
402 |
|
|
403 |
if (search != None and search != ""): |
if (search != None and search != ""): |
404 |
url = __backend__ + "&action=search&search=" + \ |
url = __backend__ + "&action=search&search=" + \ |
405 |
urllib.quote_plus(search) |
urllib.parse.quote(search) |
406 |
|
|
407 |
# print "[Todic] Search start: " + search |
# print "[Todic] Search start: " + search |
408 |
# print "[Todic] Search url: " + url |
# print "[Todic] Search url: " + url |
415 |
|
|
416 |
if (search != None and search != ""): |
if (search != None and search != ""): |
417 |
url = __backend__ + "&action=searchseries&search=" + \ |
url = __backend__ + "&action=searchseries&search=" + \ |
418 |
urllib.quote_plus(search) |
urllib.parse.quote(search) |
419 |
|
|
420 |
# print "[Todic] Search start: " + search |
# print "[Todic] Search start: " + search |
421 |
# print "[Todic] Search url: " + url |
# print "[Todic] Search url: " + url |
426 |
#=================================== Tool Box ======================================= |
#=================================== Tool Box ======================================= |
427 |
# shows a more userfriendly notification |
# shows a more userfriendly notification |
428 |
def showMessage(heading, message): |
def showMessage(heading, message): |
429 |
|
print( "[Todic::showMessage] " + str(message) ) |
430 |
|
print( message ) |
431 |
duration = 15 * 1000 |
duration = 15 * 1000 |
432 |
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % |
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % |
433 |
(heading, message, duration)) |
(heading, message, duration)) |
481 |
#print params |
#print params |
482 |
|
|
483 |
try: |
try: |
484 |
url = urllib.unquote_plus(params["url"]) |
url = urllib.parse.unquote(params["url"]) |
485 |
except: |
except: |
486 |
pass |
pass |
487 |
try: |
try: |
488 |
name = urllib.unquote_plus(params["name"]) |
name = urllib.parse.unquote(params["name"]) |
489 |
except: |
except: |
490 |
pass |
pass |
491 |
try: |
try: |
493 |
except: |
except: |
494 |
pass |
pass |
495 |
|
|
496 |
|
print( "[Todic] url=" + str(url)) |
497 |
|
print( "[Todic] name=" + str(name)) |
498 |
|
print( "[Todic] mode=" + str(mode)) |
499 |
|
|
500 |
|
|
501 |
try: |
try: |
502 |
open_url("http://todic.dk") |
open_url("https://todic.dk") |
503 |
except: |
except: |
504 |
showMessage("Fejl", "Kunne ikke forbinde til todic.dk") |
showMessage("Fejl", "Kunne ikke forbinde til todic.dk") |
505 |
exit() |
exit() |