3 |
|
|
4 |
''' |
''' |
5 |
Todic plugin for XBMC |
Todic plugin for XBMC |
6 |
Version 0.0.15 |
Version 0.0.17 |
7 |
''' |
''' |
8 |
|
|
9 |
import sys |
import sys |
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() |
100 |
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) |
xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) |
101 |
self.stopped = False |
self.stopped = False |
102 |
self.started = False |
self.started = False |
103 |
|
self.playingPosition = 0.0 |
104 |
|
self.lastReport = 0 |
105 |
print "[TodicPlayer] init" |
print "[TodicPlayer] init" |
106 |
|
|
107 |
# @catchall |
# @catchall |
110 |
print "[TodicPlayer] : started" |
print "[TodicPlayer] : started" |
111 |
# super.onPlayBackStarted() |
# super.onPlayBackStarted() |
112 |
|
|
113 |
|
#When user presses stop, we report back the the position registered in the last call to self.tick() |
114 |
def onPlayBackStopped(self): |
def onPlayBackStopped(self): |
115 |
self.stopped = True |
self.stopped = True |
116 |
print "[TodicPlayer] : stopped" |
print "[TodicPlayer] : stopped" |
117 |
|
url = __backend__ + "&action=playbacktime&subaction=stopped&time=" + str( self.playingPosition ) |
118 |
|
open_url_safe(url) |
119 |
|
|
120 |
|
|
121 |
def onPlayBackEnded(self): |
def onPlayBackEnded(self): |
122 |
self.stopped = True |
self.stopped = True |
123 |
print "[TodicPlayer] : ended" |
print "[TodicPlayer] : ended" |
124 |
|
url = __backend__ + "&action=playbacktime&subaction=ended&time=" |
125 |
|
open_url_safe(url) |
126 |
|
|
127 |
def callbackLoop(self): |
def tick(self): |
128 |
print "[Todic] startLoop" |
if ( self.isPlaying() ): |
129 |
while (self.stopped == False): |
self.playingPosition = self.getTime() |
130 |
if (self.started == True): |
now = time() |
131 |
print "[todic] " + str(self.getTime()) |
#print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) |
132 |
xbmc.sleep(5000) |
if ( (now - self.lastReport) > 60.0): |
133 |
|
self.reportPlaytime() |
134 |
|
self.lastReport = now |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
def reportPlaytime(self): |
139 |
|
url = __backend__ + "&action=playbacktime&subaction=playing&time=" + str( self.playingPosition ) |
140 |
|
open_url_safe(url) |
141 |
|
print "[Todic] reportPlaytime:" + url |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
def getText2(nodelist): |
def getText2(nodelist): |
162 |
return nodelist[0].childNodes[0].nodeValue |
return nodelist[0].childNodes[0].nodeValue |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
def SaveFile(path, data): |
def SaveFile(path, data): |
167 |
file = open(path, 'w') |
file = open(path, 'w') |
168 |
file.write(data) |
file.write(data) |
169 |
file.close() |
file.close() |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
def open_url(url): |
def open_url(url): |
174 |
req = urllib2.Request(url) |
req = urllib2.Request(url) |
175 |
content = urllib2.urlopen(req) |
content = urllib2.urlopen(req) |
178 |
return data |
return data |
179 |
|
|
180 |
|
|
181 |
|
# wraps open url in a catch-all exception handler |
182 |
|
# usefull for periodic back-reporting that should not interrupt the program flow |
183 |
|
def open_url_safe(url): |
184 |
|
try: |
185 |
|
return open_url(url) |
186 |
|
except: |
187 |
|
print "Some error during open_url call to ", url |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
def rootMenu(): |
def rootMenu(): |
192 |
|
|
193 |
msg = open_url(__backend__ + "&action=messages") |
msg = open_url(__backend__ + "&action=messages") |
331 |
else: |
else: |
332 |
player.disableSubtitles() |
player.disableSubtitles() |
333 |
|
|
334 |
|
#Holder python kørernde indtil at det bliver bedt om at stoppe |
335 |
|
while (not xbmc.abortRequested): |
336 |
|
player.tick() |
337 |
|
xbmc.sleep(100) |
338 |
|
|
339 |
|
|
340 |
|
|
341 |
# player.callbackLoop() |
# player.callbackLoop() |
342 |
|
|
343 |
|
|