--- misc/xbmc/plugin.video.todic/default.py 2015/07/13 14:33:39 2601 +++ misc/xbmc/plugin.video.todic/default.py 2016/11/23 09:36:57 3145 @@ -3,11 +3,10 @@ ''' Todic plugin for XBMC - Version 0.0.15 + Version 0.0.18 ''' import sys -import cgi as urlparse import os @@ -21,10 +20,11 @@ # import pprint from xml.dom.minidom import parseString +from time import time __addon__ = xbmcaddon.Addon(id='plugin.video.todic') __key__ = __addon__.getSetting('xbmckey').lower() -__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ +__backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__ fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') datapath = xbmc.translatePath( 'special://profile/addon_data/plugin.video.todic/') @@ -100,6 +100,8 @@ xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) self.stopped = False self.started = False + self.playingPosition = 0.0 + self.lastReport = 0 print "[TodicPlayer] init" # @catchall @@ -108,20 +110,36 @@ print "[TodicPlayer] : started" # super.onPlayBackStarted() + #When user presses stop, we report back the the position registered in the last call to self.tick() def onPlayBackStopped(self): self.stopped = True print "[TodicPlayer] : stopped" + url = __backend__ + "&action=playbacktime&subaction=stopped&time=" + str( self.playingPosition ) + open_url_safe(url) + def onPlayBackEnded(self): self.stopped = True print "[TodicPlayer] : ended" + url = __backend__ + "&action=playbacktime&subaction=ended&time=" + open_url_safe(url) - def callbackLoop(self): - print "[Todic] startLoop" - while (self.stopped == False): - if (self.started == True): - print "[todic] " + str(self.getTime()) - xbmc.sleep(5000) + def tick(self): + if ( self.isPlaying() ): + self.playingPosition = self.getTime() + now = time() + #print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) + if ( (now - self.lastReport) > 60.0): + self.reportPlaytime() + self.lastReport = now + + + + def reportPlaytime(self): + url = __backend__ + "&action=playbacktime&subaction=playing&time=" + str( self.playingPosition ) + open_url_safe(url) + print "[Todic] reportPlaytime:" + url + def getText2(nodelist): @@ -144,12 +162,14 @@ return nodelist[0].childNodes[0].nodeValue + def SaveFile(path, data): file = open(path, 'w') file.write(data) file.close() + def open_url(url): req = urllib2.Request(url) content = urllib2.urlopen(req) @@ -158,6 +178,16 @@ return data +# wraps open url in a catch-all exception handler +# usefull for periodic back-reporting that should not interrupt the program flow +def open_url_safe(url): + try: + return open_url(url) + except: + print "Some error during open_url call to ", url + + + def rootMenu(): msg = open_url(__backend__ + "&action=messages") @@ -175,7 +205,7 @@ listitem.setProperty('Fanart_Image', fanartImage) u = sys.argv[0] + "?mode=10&name=" - ok = xbmcplugin.addDirectoryItem( + xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) # add search series @@ -184,7 +214,7 @@ listitem.setProperty('Fanart_Image', fanartImage) u = sys.argv[0] + "?mode=11&name=" - ok = xbmcplugin.addDirectoryItem( + xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True) xbmcplugin.endOfDirectory(int(sys.argv[1])) @@ -238,7 +268,7 @@ u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote( name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) - ok = xbmcplugin.addDirectoryItem( + xbmcplugin.addDirectoryItem( handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=folder, totalItems=l) if (endlist == True): @@ -301,6 +331,13 @@ else: player.disableSubtitles() + #Holder python kørernde indtil at det bliver bedt om at stoppe + while (not xbmc.abortRequested): + player.tick() + xbmc.sleep(100) + + + # player.callbackLoop()