3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 0.0.15 |
Version 0.0.20 |
7 |
''' |
''' |
8 |
|
|
9 |
import sys |
import sys |
|
import cgi as urlparse |
|
10 |
import os |
import os |
11 |
|
|
12 |
|
|
20 |
# import pprint |
# import pprint |
21 |
|
|
22 |
from xml.dom.minidom import parseString |
from xml.dom.minidom import parseString |
23 |
|
from time import time |
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 |
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ |
__backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__ |
28 |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') |
29 |
datapath = xbmc.translatePath( |
datapath = xbmc.translatePath( |
30 |
'special://profile/addon_data/plugin.video.todic/') |
'special://profile/addon_data/plugin.video.todic/') |
42 |
|
|
43 |
def __init__(self): |
def __init__(self): |
44 |
super(TodicMovieDialog, self).__init__() |
super(TodicMovieDialog, self).__init__() |
45 |
|
self.position = 0 |
46 |
|
|
47 |
def onClick(self, controlId): |
def onClick(self, controlId): |
48 |
print "OnClick: " + str(controlId) |
print "[Todic] MovieDialog OnClick: " + str(controlId) |
49 |
|
|
50 |
if (controlId == 50): |
if (controlId == 50): |
51 |
self.close() |
self.close() |
52 |
play_real_video(self.url, self.name) |
play_real_video(self.url, self.name, 0) |
53 |
|
|
54 |
|
if (controlId == 51): |
55 |
|
self.close() |
56 |
|
play_real_video(self.url, self.name, self.position) |
57 |
|
|
58 |
if (controlId == 98): |
if (controlId == 98): |
59 |
self.close() |
self.close() |
60 |
|
|
61 |
def onInit(self): |
def onInit(self): |
62 |
|
|
63 |
print "ONINIT" |
print "[Todic] MovieDialog ONINIT" |
64 |
self.getControl(1).setLabel(self.name) |
self.getControl(1).setLabel(self.name) |
65 |
self.getControl(2).setLabel(self.moviegroups) |
self.getControl(2).setLabel(self.moviegroups) |
66 |
self.getControl(3).setLabel(self.description) |
self.getControl(3).setLabel(self.description) |
67 |
self.getControl(10).setLabel(self.playlength) |
self.getControl(10).setLabel(self.playlength) |
68 |
self.getControl(11).setLabel(self.codecdetails) |
self.getControl(11).setLabel(self.codecdetails) |
69 |
|
|
70 |
orig_img_width = self.getControl(40).getWidth() |
if (self.position > 0): |
71 |
self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width |
self.getControl(51).setVisible(True) |
72 |
self.getControl(40).setWidth(int(self.starwidth)) |
self.getControl(50).setPosition(100, 570) |
73 |
|
self.getControl(51).setPosition(450, 570) |
74 |
|
self.getControl(50).controlLeft( self.getControl(51) ) |
75 |
|
self.getControl(50).controlRight( self.getControl(51) ) |
76 |
|
else: |
77 |
|
self.getControl(51).setVisible(False) |
78 |
|
|
79 |
|
#orig_img_width = self.getControl(40).getWidth() |
80 |
|
#self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width |
81 |
|
#self.getControl(40).setWidth(int(self.starwidth)) |
82 |
|
|
83 |
def setUrl(self, url): |
def setUrl(self, url): |
84 |
print "SETURL:" + url |
print "[Todic] MovieDialog SETURL:" + url |
85 |
self.url = url |
self.url = url |
86 |
self.fetchClipDetails() |
self.fetchClipDetails() |
87 |
|
|
88 |
|
def setPosition(self, pos): |
89 |
|
print "[Todic] MovieDialog setPosition:" + str(pos) |
90 |
|
self.position = pos |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
def fetchClipDetails(self): |
def fetchClipDetails(self): |
95 |
param1 = parse_parameter_string(self.url) |
param1 = parse_parameter_string(self.url) |
96 |
|
|
120 |
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) |
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) |
121 |
self.stopped = False |
self.stopped = False |
122 |
self.started = False |
self.started = False |
123 |
|
self.playingPosition = 0.0 |
124 |
|
self.lastReport = 0 |
125 |
print "[TodicPlayer] init" |
print "[TodicPlayer] init" |
126 |
|
|
127 |
# @catchall |
# @catchall |
130 |
print "[TodicPlayer] : started" |
print "[TodicPlayer] : started" |
131 |
# super.onPlayBackStarted() |
# super.onPlayBackStarted() |
132 |
|
|
133 |
|
#When user presses stop, we report back the the position registered in the last call to self.tick() |
134 |
def onPlayBackStopped(self): |
def onPlayBackStopped(self): |
135 |
self.stopped = True |
self.stopped = True |
136 |
print "[TodicPlayer] : stopped" |
print "[TodicPlayer] : stopped" |
137 |
|
url = __backend__ + "&action=playbacktime&subaction=stopped&time=" + str( self.playingPosition ) |
138 |
|
open_url_safe(url) |
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=" |
145 |
|
open_url_safe(url) |
146 |
|
|
147 |
def callbackLoop(self): |
def tick(self): |
148 |
print "[Todic] startLoop" |
if ( self.isPlaying() ): |
149 |
while (self.stopped == False): |
self.playingPosition = self.getTime() |
150 |
if (self.started == True): |
now = time() |
151 |
print "[todic] " + str(self.getTime()) |
#print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) |
152 |
xbmc.sleep(5000) |
if ( (now - self.lastReport) > 60.0): |
153 |
|
self.lastReport = now |
154 |
|
self.reportPlaytime() |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
def reportPlaytime(self): |
160 |
|
url = __backend__ + "&action=playbacktime&subaction=playing&time=" + str( self.playingPosition ) |
161 |
|
open_url_safe(url) |
162 |
|
print "[Todic] reportPlaytime:" + url |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
def getText2(nodelist): |
def getText2(nodelist): |
183 |
return nodelist[0].childNodes[0].nodeValue |
return nodelist[0].childNodes[0].nodeValue |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
def SaveFile(path, data): |
def SaveFile(path, data): |
188 |
file = open(path, 'w') |
file = open(path, 'w') |
189 |
file.write(data) |
file.write(data) |
190 |
file.close() |
file.close() |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
def open_url(url): |
def open_url(url): |
195 |
req = urllib2.Request(url) |
req = urllib2.Request(url) |
196 |
content = urllib2.urlopen(req) |
content = urllib2.urlopen(req) |
199 |
return data |
return data |
200 |
|
|
201 |
|
|
202 |
|
# wraps open url in a catch-all exception handler |
203 |
|
# usefull for periodic back-reporting that should not interrupt the program flow |
204 |
|
def open_url_safe(url): |
205 |
|
try: |
206 |
|
return open_url(url) |
207 |
|
except: |
208 |
|
print "[Todic ]Some error during open_url call to ", url |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
def rootMenu(): |
def rootMenu(): |
213 |
|
|
214 |
msg = open_url(__backend__ + "&action=messages") |
msg = open_url(__backend__ + "&action=messages") |
226 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
227 |
|
|
228 |
u = sys.argv[0] + "?mode=10&name=" |
u = sys.argv[0] + "?mode=10&name=" |
229 |
ok = xbmcplugin.addDirectoryItem( |
xbmcplugin.addDirectoryItem( |
230 |
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
231 |
|
|
232 |
# add search series |
# add search series |
235 |
listitem.setProperty('Fanart_Image', fanartImage) |
listitem.setProperty('Fanart_Image', fanartImage) |
236 |
|
|
237 |
u = sys.argv[0] + "?mode=11&name=" |
u = sys.argv[0] + "?mode=11&name=" |
238 |
ok = xbmcplugin.addDirectoryItem( |
xbmcplugin.addDirectoryItem( |
239 |
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) |
240 |
|
|
241 |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
xbmcplugin.endOfDirectory(int(sys.argv[1])) |
265 |
thumb = getText(entry.getElementsByTagName("cover")) |
thumb = getText(entry.getElementsByTagName("cover")) |
266 |
description = getText(entry.getElementsByTagName("description")) |
description = getText(entry.getElementsByTagName("description")) |
267 |
playcount = getText(entry.getElementsByTagName("playcount")) |
playcount = getText(entry.getElementsByTagName("playcount")) |
268 |
|
pos = getText(entry.getElementsByTagName("pos")) |
269 |
|
|
270 |
|
|
271 |
if playcount == '': |
if playcount == '': |
272 |
playcount = '0' |
playcount = '0' |
290 |
description = description.encode('UTF-8') |
description = description.encode('UTF-8') |
291 |
|
|
292 |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( |
293 |
name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) |
name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) + "&pos=" + pos |
294 |
ok = xbmcplugin.addDirectoryItem( |
xbmcplugin.addDirectoryItem( |
295 |
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) |
296 |
|
|
297 |
if (endlist == True): |
if (endlist == True): |
300 |
|
|
301 |
def play_video(url, name, description): |
def play_video(url, name, description): |
302 |
if (description == None or description == ""): |
if (description == None or description == ""): |
303 |
play_real_video(url, name) |
play_real_video(url, name, 0) |
304 |
else: |
else: |
305 |
d = TodicMovieDialog() |
d = TodicMovieDialog() |
306 |
d.setUrl(url) |
d.setUrl(url) |
307 |
d.setName(name) |
d.setName(name) |
308 |
d.setDescription(description) |
d.setDescription(description) |
309 |
|
d.setPosition(pos) #tager pos fra global scope |
310 |
|
|
311 |
d.doModal() |
d.doModal() |
312 |
|
|
313 |
|
|
314 |
def play_real_video(url, name): |
def play_real_video(url, name, position): |
315 |
xml = open_url(url) |
xml = open_url(url) |
316 |
print 'TODIC url: ' + str(url) |
print '[Todic] url: ' + str(url) |
317 |
print 'TODIC xml: ' + xml |
print '[Todic] xml: ' + xml |
318 |
|
print '[Todic] pos: ' + str(position) |
319 |
|
|
320 |
doc = parseString(xml) |
doc = parseString(xml) |
321 |
url = getText(doc.getElementsByTagName("url")) |
url = getText(doc.getElementsByTagName("url")) |
337 |
listitem = xbmcgui.ListItem( |
listitem = xbmcgui.ListItem( |
338 |
label=name, iconImage='DefaultVideo.png', thumbnailImage=image) |
label=name, iconImage='DefaultVideo.png', thumbnailImage=image) |
339 |
listitem.setInfo(type="Video", infoLabels={"Title": name}) |
listitem.setInfo(type="Video", infoLabels={"Title": name}) |
340 |
|
listitem.setProperty('ResumeTime', '300') |
341 |
|
listitem.setProperty('TotalTime', '3000') |
342 |
|
|
343 |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) |
344 |
player.play(str(url), listitem) |
player.play(str(url), listitem) |
346 |
# kan ikke loade subtitles hvis foerend playeren koerer |
# kan ikke loade subtitles hvis foerend playeren koerer |
347 |
count = 0 |
count = 0 |
348 |
while not xbmc.Player().isPlaying(): |
while not xbmc.Player().isPlaying(): |
349 |
xbmc.sleep(500) |
xbmc.sleep(250) |
350 |
count += 1 |
count += 1 |
351 |
if count > 10: |
if count > 10: |
352 |
break |
break |
353 |
|
|
354 |
|
|
355 |
|
|
356 |
if xbmc.Player().isPlaying(): |
if xbmc.Player().isPlaying(): |
357 |
if os.path.isfile(subtitlesfile): |
if os.path.isfile(subtitlesfile): |
358 |
player.setSubtitles(subtitlesfile) |
player.setSubtitles(subtitlesfile) |
360 |
else: |
else: |
361 |
player.disableSubtitles() |
player.disableSubtitles() |
362 |
|
|
363 |
# player.callbackLoop() |
|
364 |
|
if (position > 0): |
365 |
|
while (player.getTotalTime() == 0.0): #Vent indtil vi har beregnet hvor langt klippet er |
366 |
|
xbmc.sleep(250) |
367 |
|
|
368 |
|
print "[Todic] totalTime " + str( player.getTotalTime() ) |
369 |
|
player.seekTime(position) |
370 |
|
|
371 |
|
|
372 |
|
#Holder python kørernde indtil at det bliver bedt om at stoppe |
373 |
|
while (not xbmc.abortRequested): |
374 |
|
player.tick() |
375 |
|
xbmc.sleep(500) |
376 |
|
|
377 |
|
|
378 |
|
|
379 |
def search(): |
def search(): |
454 |
name = None |
name = None |
455 |
mode = None |
mode = None |
456 |
description = None |
description = None |
457 |
|
pos = 0 |
458 |
|
|
459 |
|
#print params |
460 |
|
|
461 |
try: |
try: |
462 |
url = urllib.unquote_plus(params["url"]) |
url = urllib.unquote_plus(params["url"]) |
475 |
except: |
except: |
476 |
pass |
pass |
477 |
|
|
478 |
|
|
479 |
|
|
480 |
|
try: |
481 |
|
pos = int(params["pos"]) |
482 |
|
except: |
483 |
|
pass |
484 |
|
|
485 |
|
|
486 |
try: |
try: |
487 |
open_url("http://todic.dk") |
open_url("http://todic.dk") |
488 |
except: |
except: |