def run(): player = MyPlayer() if player is None: xbmclog('Kodi Hue: In run() could not instantiate player') return while not monitor.abortRequested(): if len(hue.ambilight_controller.lights) and not ev.is_set(): startReadOut = False vals = {} if player.playingvideo: # only if there's actually video try: vals = capture.getImage(200) if len(vals) > 0 and player.playingvideo: startReadOut = True if startReadOut: screen = image.Screenshot(capture.getImage()) hsv_ratios = screen.spectrum_hsv( screen.pixels, hue.settings.ambilight_threshold_value, hue.settings.ambilight_threshold_saturation, hue.settings.color_bias, len(hue.ambilight_controller.lights)) for i in range(len(hue.ambilight_controller.lights)): algorithm.transition_colorspace( hue, hue.ambilight_controller.lights.values()[i], hsv_ratios[i], ) except ZeroDivisionError: pass if monitor.waitForAbort(0.1): xbmclog('Kodi Hue: In run() deleting player') del player # might help with slow exit.
def run(): player = MyPlayer() if player is None: xbmclog('Kodi Hue: In run() could not instantiate player') return while not monitor.abortRequested(): if len(hue.ambilight_controller.lights) and not ev.is_set(): startReadOut = False vals = {} if player.playingvideo: # only if there's actually video try: vals = capture.getImage(200) if len(vals) > 0 and player.playingvideo: startReadOut = True if startReadOut: screen = image.Screenshot( capture.getImage()) hsv_ratios = screen.spectrum_hsv( screen.pixels, hue.settings.ambilight_threshold_value, hue.settings.ambilight_threshold_saturation, hue.settings.color_bias, len(hue.ambilight_controller.lights) ) for i in range(len(hue.ambilight_controller.lights)): algorithm.transition_colorspace( hue, hue.ambilight_controller.lights.values()[i], hsv_ratios[i], ) except ZeroDivisionError: pass if monitor.waitForAbort(0.1): xbmclog('Kodi Hue: In run() deleting player') del player # might help with slow exit.
def run(self): while not self.monitor.abortRequested(): if len(self.ambilight_controller.lights) and not ev.is_set(): startReadOut = False vals = {} if self.player.playingvideo: # only if there's actually video # ping metrics server to keep sessions alive while playing # ping every 5 min timeSinceLastPing = time.time() - self.lastMetricPing if (timeSinceLastPing > 300): self.lastMetricPing = time.time() ga = GoogleAnalytics() # Keep the session alive ga.sendEventData("Playback", "Playing", "Video", None, 1) try: pixels = capture.getImage(200) if len(pixels) > 0: screen = image.Screenshot(pixels) hsv_ratios = screen.spectrum_hsv( screen.pixels, self.settings.ambilight_threshold_value, self.settings.ambilight_threshold_saturation, self.settings.color_variation, self.settings.color_bias, len(self.ambilight_controller.lights)) for i in range( len(self.ambilight_controller.lights)): algorithm.transition_colorspace( self, self.ambilight_controller.lights.values() [i], hsv_ratios[i], ) except ZeroDivisionError: pass # Sleep for 0.1s if self.monitor.waitForAbort( 0.1 if self.player.playingvideo else 1): # Abort was requested while waiting. We should exit break