def poll(self): while not XBMCMonitor.abortRequested(self): if XBMCMonitor.waitForAbort(self, INTERVAL): break if self.SettingsChanged: self.getSettings() _now = time.time() timers = handler.readTimerStrings() for _timer in timers: if not _timer['utime']: handler.notifyLog('Couldn\'t calculate timestamp, delete timer', xbmc.LOGERROR) self.resetSwitchTimer(_timer['channel'], _timer['date']) break # delete old/discarded timers if _timer['utime'] + self.__discardTmr < _now: self.resetSwitchTimer(_timer['channel'], _timer['date']) continue _timediff = INTERVAL + self.__dispMsgTime/1000 if _timer['utime'] - _now < _timediff: chanIdTmr = self.channelName2channelId(_timer['channel'].decode('utf-8')) if chanIdTmr: # get player properties, switch if necessary plrProps = self.getPlayer() if chanIdTmr == plrProps['id']: handler.notifyLog('Channel switching unnecessary') handler.notifyOSD(__LS__(30000), __LS__(30027) % (_timer['channel'].decode('utf-8')), time=self.__dispMsgTime) else: switchAborted = False secs = 0 handler.notifyLog('Channel switch to %s required' % (_timer['channel'].decode('utf-8'))) if self.__showNoticeBeforeSw: if self.__useCountdownTimer: percent = 0 handler.OSDProgress.create(__LS__(30028), _timer['channel'].decode('utf-8'), _timer['title'].decode('utf-8'), __LS__(30029) % (int(self.__dispMsgTime/1000 - secs))) while secs < self.__dispMsgTime/1000: secs += 1 percent = int((secs * 100)/self.__dispMsgTime) handler.OSDProgress.update(percent, _timer['channel'].decode('utf-8'), _timer['title'].decode('utf-8'), __LS__(30029) % (int(self.__dispMsgTime/1000 - secs))) xbmc.sleep(1000) if (handler.OSDProgress.iscanceled()): switchAborted = True break handler.OSDProgress.close() else: idleTime = xbmc.getGlobalIdleTime() handler.notifyOSD(__LS__(30000), __LS__(30026) % (_timer['channel'].decode('utf-8')), time=self.__dispMsgTime) # wait for for cancelling by user (Ennieki ;) while secs < self.__dispMsgTime/1000: if idleTime > xbmc.getGlobalIdleTime(): switchAborted = True break xbmc.sleep(1000) idleTime += 1 secs += 1 else: xbmc.sleep(self.__dispMsgTime) if switchAborted: handler.notifyLog('Channelswitch cancelled by user') else: if plrProps['player'] == 'audio' or (plrProps['player'] == 'video' and plrProps['media'] != 'channel'): # stop all other players except pvr handler.notifyLog('player:%s media:%s @id:%s is running' % (plrProps['player'], plrProps['media'], plrProps['playerid'])) query = { "jsonrpc": "2.0", "method": "Player.Stop", "params": {"playerid": plrProps['playerid']}, "id": 1 } res = jsonrpc(query) if 'result' in res and res['result'] == "OK": handler.notifyLog('Player stopped') handler.notifyLog('Currently playing channelid %s, switch to id %s' % (plrProps['id'], chanIdTmr)) query = { "jsonrpc": "2.0", "id": 1, "method": "Player.Open", "params": {"item": {"channelid": chanIdTmr}} } res = jsonrpc(query) if 'result' in res and res['result'] == 'OK': handler.notifyLog('Switched to channel \'%s\'' % (_timer['channel'].decode('utf-8'))) else: handler.notifyLog('Couldn\'t switch to channel \'%s\'' % (_timer['channel'].decode('utf-8'))) handler.notifyOSD(__LS__(30000), __LS__(30025) % (_timer['channel'].decode('utf-8')), icon=__IconAlert__) self.resetSwitchTimer(_timer['channel'], _timer['date']) handler.notifyLog('Timer @%s deactivated' % (_timer['date'])) handler.notifyLog('Service kicks off')
def poll(self): while not XBMCMonitor.abortRequested(self): if XBMCMonitor.waitForAbort(self, INTERVAL): break if self.SettingsChanged: self.getSettings() _now = time.time() timers = handler.readTimerStrings() for _timer in timers: if not _timer['utime']: handler.notifyLog( 'Couldn\'t calculate timestamp, delete timer', xbmc.LOGERROR) self.resetSwitchTimer(_timer['channel'], _timer['date']) break # delete old/discarded timers if _timer['utime'] + self.__discardTmr < _now: self.resetSwitchTimer(_timer['channel'], _timer['date']) continue _timediff = INTERVAL + self.__dispMsgTime / 1000 if _timer['utime'] - _now < _timediff: chanIdTmr = self.channelName2channelId( _timer['channel'].decode('utf-8')) if chanIdTmr: # get player properties, switch if necessary plrProps = self.getPlayer() if chanIdTmr == plrProps['id']: handler.notifyLog('Channel switching unnecessary') handler.notifyOSD( __LS__(30000), __LS__(30027) % (_timer['channel'].decode('utf-8')), time=self.__dispMsgTime) else: switchAborted = False secs = 0 handler.notifyLog( 'Channel switch to %s required' % (_timer['channel'].decode('utf-8'))) if self.__showNoticeBeforeSw: if self.__useCountdownTimer: percent = 0 handler.OSDProgress.create( __LS__(30028), __LS__(30026) % _timer['channel'].decode('utf-8'), __LS__(30029) % (int(self.__dispMsgTime / 1000 - secs))) while secs < self.__dispMsgTime / 1000: secs += 1 percent = int((secs * 100000) / self.__dispMsgTime) handler.OSDProgress.update( percent, __LS__(30026) % _timer['channel'].decode('utf-8'), __LS__(30029) % (int(self.__dispMsgTime / 1000 - secs))) xbmc.sleep(1000) if (handler.OSDProgress.iscanceled()): switchAborted = True break handler.OSDProgress.close() else: idleTime = xbmc.getGlobalIdleTime() handler.notifyOSD( __LS__(30000), __LS__(30026) % (_timer['channel'].decode('utf-8')), time=self.__dispMsgTime) # wait for for cancelling by user (Ennieki ;) while secs < self.__dispMsgTime / 1000: if idleTime > xbmc.getGlobalIdleTime(): switchAborted = True break xbmc.sleep(1000) idleTime += 1 secs += 1 else: xbmc.sleep(self.__dispMsgTime) if switchAborted: handler.notifyLog( 'Channelswitch cancelled by user') else: if plrProps['player'] == 'audio' or ( plrProps['player'] == 'video' and plrProps['media'] != 'channel'): # stop all other players except pvr handler.notifyLog( 'player:%s media:%s @id:%s is running' % (plrProps['player'], plrProps['media'], plrProps['playerid'])) query = { "jsonrpc": "2.0", "method": "Player.Stop", "params": { "playerid": plrProps['playerid'] }, "id": 1 } res = jsonrpc(query) if 'result' in res and res[ 'result'] == "OK": handler.notifyLog('Player stopped') handler.notifyLog( 'Currently playing channelid %s, switch to id %s' % (plrProps['id'], chanIdTmr)) query = { "jsonrpc": "2.0", "id": 1, "method": "Player.Open", "params": { "item": { "channelid": chanIdTmr } } } res = jsonrpc(query) if 'result' in res and res['result'] == 'OK': handler.notifyLog( 'Switched to channel \'%s\'' % (_timer['channel'].decode('utf-8'))) else: handler.notifyLog( 'Couldn\'t switch to channel \'%s\'' % (_timer['channel'].decode('utf-8'))) handler.notifyOSD( __LS__(30000), __LS__(30025) % (_timer['channel'].decode('utf-8')), icon=__IconAlert__) self.resetSwitchTimer(_timer['channel'], _timer['date']) handler.notifyLog('Timer @%s deactivated' % (_timer['date'])) handler.notifyLog('Service kicks off')
def poll(self): while not XBMCMonitor.abortRequested(self): if XBMCMonitor.waitForAbort(self, INTERVAL): break if self.SettingsChanged: self.getSettings() _now = time.time() timers = handler.readTimerStrings() for _timer in timers: if not _timer["utime"]: handler.notifyLog("Couldn't calculate timestamp, delete timer", xbmc.LOGERROR) self.resetSwitchTimer(_timer["channel"], _timer["date"]) break # delete old/discarded timers if _timer["utime"] + self.__discardTmr < _now: self.resetSwitchTimer(_timer["channel"], _timer["date"]) continue _timediff = INTERVAL + self.__dispMsgTime / 1000 if _timer["utime"] - _now < _timediff: chanIdTmr = self.channelName2channelId(_timer["channel"].decode("utf-8")) if chanIdTmr: # get player properties, switch if necessary plrProps = self.getPlayer() if chanIdTmr == plrProps["id"]: handler.notifyLog("Channel switching not required") handler.notifyOSD( __LS__(30000), __LS__(30027) % (_timer["channel"].decode("utf-8")), time=self.__dispMsgTime, ) else: idleTime = xbmc.getGlobalIdleTime() countdown = 0 switchAborted = False handler.notifyLog("Channel switch to " + _timer["channel"].decode("utf-8") + "required") if self.__useCountdownTimer: # TODO: # - only check every 30s, this should be enough, see line 24 # - the switch dialog should appear @ starttime minus 30s minus dialog-displaytime # then the user has enough time to react # - translate "Switch to channel" and "seconds left". I'm too lazy right now ;) ret = msgdialogprogress.create( "Channel switch requested", "Switch to Channel:" + (_timer["channel"].decode("utf-8")), ) secs = 0 percent = 0 time_to_wait = self.__dispMsgTime # use the multiplier 100 to get better %/calculation increment = 100 * 100 / time_to_wait cancelled = False while secs < time_to_wait: secs = secs + 1 # divide with 100, to get the right value percent = increment * secs / 100 secs_left = str((time_to_wait - secs)) remaining_display = str(secs_left) + " seconds left." msgdialogprogress.update( percent, str(_timer["channel"].decode("utf-8")), str(_timer["title"].decode("utf-8")), remaining_display, ) xbmc.sleep(1000) if msgdialogprogress.iscanceled(): switchAborted = True break msgdialogprogress.close() else: handler.notifyOSD( __LS__(30000), __LS__(30026) % (_timer["channel"].decode("utf-8")), time=self.__dispMsgTime, ) # wait for for cancelling by user (Ennieki ;) while countdown < self.__dispMsgTime / 1000: if idleTime > xbmc.getGlobalIdleTime(): switchAborted = True break xbmc.sleep(1000) idleTime += 1 countdown += 1 if switchAborted: handler.notifyLog("Channelswitch cancelled by user") else: if plrProps["player"] == "audio" or ( plrProps["player"] == "video" and plrProps["media"] != "channel" ): # stop the media player handler.notifyLog( "player:%s media:%s @id:%s is running" % (plrProps["player"], plrProps["media"], plrProps["playerid"]) ) query = { "jsonrpc": "2.0", "method": "Player.Stop", "params": {"playerid": plrProps["playerid"]}, "id": 1, } res = jsonrpc(query) # is this faster? # xbmc.executebuiltin('PlayerControl(Stop)') if "result" in res and res["result"] == "OK": handler.notifyLog("Player stopped") handler.notifyLog( "Currently playing channelid %s, switch to id %s" % (plrProps["id"], chanIdTmr) ) query = { "jsonrpc": "2.0", "id": 1, "method": "Player.Open", "params": {"item": {"channelid": chanIdTmr}}, } res = jsonrpc(query) if "result" in res and res["result"] == "OK": handler.notifyLog("Switched to channel '%s'" % (_timer["channel"].decode("utf-8"))) else: handler.notifyLog( "Couldn't switch to channel '%s'" % (_timer["channel"].decode("utf-8")) ) handler.notifyOSD( __LS__(30000), __LS__(30025) % (_timer["channel"].decode("utf-8")), icon=__IconAlert__, ) self.resetSwitchTimer(_timer["channel"], _timer["date"]) handler.notifyLog("Timer @%s deactivated" % (_timer["date"])) handler.notifyLog("Service kicks off")