Пример #1
0
 def check(self):
     if Settings.autoPauseSonos() and not Settings.linkAudioWithSonos():
         try:
             # Check to see if something has started playing
             if xbmc.Player().isPlaying():
                 # If this is a change in play state since the last time we checked
                 if self.xbmcPlayState is False:
                     log("SonosAutoPause: Automatically pausing Sonos")
                     self.xbmcPlayState = True
                     # Pause the sonos if it is playing
                     if self._isSonosPlaying():
                         self.sonosDevice.pause()
                         self.autoStopped = True
                         self.resumeCountdown = Settings.autoResumeSonos()
             else:
                 self.xbmcPlayState = False
                 if Settings.autoResumeSonos() > 0 and self.autoStopped:
                     if self.resumeCountdown > 0:
                         self.resumeCountdown = self.resumeCountdown - 1
                     else:
                         log("SonosAutoPause: Automatically resuming Sonos")
                         self.sonosDevice.play()
                         self.autoStopped = False
                         self.resumeCountdown = Settings.autoResumeSonos()
         except:
             # If we fail to stop the speaker playing, it may be because
             # there is a network problem or the speaker is powered down
             # So we just continue after logging the error
             log("SonosAutoPause: Error from speaker %s" %
                 Settings.getIPAddress())
             log("SonosAutoPause: %s" % traceback.format_exc())
Пример #2
0
 def check(self):
     if Settings.autoPauseSonos() and not Settings.linkAudioWithSonos():
         try:
             # Check to see if something has started playing
             if xbmc.Player().isPlaying():
                 # If this is a change in play state since the last time we checked
                 if self.xbmcPlayState is False:
                     log("SonosAutoPause: Automatically pausing Sonos")
                     self.xbmcPlayState = True
                     # Pause the sonos if it is playing
                     if self._isSonosPlaying():
                         self.sonosDevice.pause()
                         self.autoStopped = True
                         self.resumeCountdown = Settings.autoResumeSonos()
             else:
                 self.xbmcPlayState = False
                 if Settings.autoResumeSonos() > 0 and self.autoStopped:
                     if self.resumeCountdown > 0:
                         self.resumeCountdown = self.resumeCountdown - 1
                     else:
                         log("SonosAutoPause: Automatically resuming Sonos")
                         self.sonosDevice.play()
                         self.autoStopped = False
                         self.resumeCountdown = Settings.autoResumeSonos()
         except:
             # If we fail to stop the speaker playing, it may be because
             # there is a network problem or the speaker is powered down
             # So we just continue after logging the error
             log("SonosAutoPause: Error from speaker %s" % Settings.getIPAddress())
             log("SonosAutoPause: %s" % traceback.format_exc())
Пример #3
0
 def _switchToLineIn(self):
     # Check if we need to ensure the Sonos system is using the line-in
     try:
         # Not all speakers support line-in - so catch exception
         self.sonosDevice.switch_to_line_in()
         # Once switch to line in, some systems require that a play command is sent
         self.sonosDevice.play()
     except:
         log("SonosService: Failed to switch to Line-In for speaker %s" % Settings.getIPAddress())
         log("SonosService: %s" % traceback.format_exc())
Пример #4
0
 def _switchToLineIn(self):
     # Check if we need to ensure the Sonos system is using the line-in
     try:
         # Not all speakers support line-in - so catch exception
         self.sonosDevice.switch_to_line_in()
         # Once switch to line in, some systems require that a play command is sent
         self.sonosDevice.play()
     except:
         log("SonosService: Failed to switch to Line-In for speaker %s" %
             Settings.getIPAddress())
         log("SonosService: %s" % traceback.format_exc())
Пример #5
0
    def __init__(self):
        # Check if the auto update IP is enabled
        if not Settings.isAutoIpUpdateEnabled():
            return

        # Get the existing zone we are trying to set the IP Address for
        existingZone = Settings.getZoneName()

        # Nothing to do if there is no Zone name set
        if (existingZone is None) or (existingZone == ""):
            return

        # Set up the logging before using the Sonos Device
        SocoLogging.enable()

        try:
            sonos_devices = discover()
        except:
            log("AutoUpdateIPAddress: Exception when getting devices")
            log("AutoUpdateIPAddress: %s" % traceback.format_exc())
            sonos_devices = []

        if sonos_devices is None:
            log("AutoUpdateIPAddress: Failed to find any devices")
            sonos_devices = []

        ipaddresses = []

        # Check each of the devices found
        for device in sonos_devices:
            ip = device.ip_address
            log("AutoUpdateIPAddress: Getting info for IP address %s" % ip)

            playerInfo = None

            # Try and get the player info, if it fails then it is not a valid
            # player and we should continue to the next
            try:
                playerInfo = device.get_speaker_info()
            except:
                log("AutoUpdateIPAddress: IP address %s is not a valid player"
                    % ip)
                log("AutoUpdateIPAddress: %s" % traceback.format_exc())
                continue

            # If player  info was found, then print it out
            if playerInfo is not None:
                # What is the name of the zone that this speaker is in?
                zone_name = playerInfo['zone_name']

                # Check the zone against the ones we are looking for
                if zone_name == existingZone:
                    # There could be multiple IP addressing in the same group
                    # so save them all
                    log("AutoUpdateIPAddress: IP address %s in zone %s" %
                        (ip, existingZone))
                    ipaddresses.append(ip)

        # Check if there is an IP Address to set
        if len(ipaddresses) > 0:
            oldIp = Settings.getIPAddress()
            # Check if we already have a match to the existing IP Address
            matchesExisting = False
            for newIp in ipaddresses:
                if newIp == oldIp:
                    matchesExisting = True
                    break
            # If no match found - then set to the first IP Address
            if not matchesExisting:
                log("AutoUpdateIPAddress: Setting IP address to %s" %
                    ipaddresses[0])
                Settings.setIPAddress(ipaddresses[0])
Пример #6
0
                                            # Gotham allows you to have a dialog without making a sound
                                            xbmcgui.Dialog().notification(
                                                track['artist'],
                                                track['title'], albumArt,
                                                Settings.
                                                getNotificationDisplayDuration(
                                                ), False)
                                        else:
                                            sonosPopup = SonosPlayingPopup.createSonosPlayingPopup(
                                                track)
                                            sonosPopup.showPopup()
                                            del sonosPopup
                            except:
                                # Connection failure - may just be a network glitch - so don't exit
                                log("SonosService: Error from speaker %s" %
                                    Settings.getIPAddress())
                                log("SonosService: %s" %
                                    traceback.format_exc())

                            # No longer the first start
                            justStartedService = False

                        # Reset the timer for the next check
                        timeUntilNextCheck = Settings.getNotificationCheckFrequency(
                        ) * Settings.getChecksPerSecond()

                    # Increment the timer and sleep for a second before the next check
                    xbmc.sleep(1000 / Settings.getChecksPerSecond())
                    timeUntilNextCheck = timeUntilNextCheck - 1

                redirectVolume.cleanup()
Пример #7
0
                    # Wait a second or so before updating
                    xbmc.sleep(Settings.getRefreshInterval())

                    stopScreensaver = stopScreensaver - Settings.getRefreshInterval()
                    if stopScreensaver < 0:
                        # A bit of a hack, but we need Kodi to think a user is "doing things" so
                        # that it does not start the screensaver, so we just send the message
                        # to open the Context menu - which in our case will do nothing
                        # but it does make Kodi think the user has done something
                        json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Input.ContextMenu", "id": 1}')
                        stopScreensaver = 40000

            except:
                # Failed to connect to the Sonos Speaker
                log("Sonos: Exception Details: %s" % traceback.format_exc(), xbmc.LOGERROR)
                xbmcgui.Dialog().ok(ADDON.getLocalizedString(32001), (ADDON.getLocalizedString(32066) % Settings.getIPAddress()))

            # Need to check to see if we can stop any subscriptsions
            if sub is not None:
                try:
                    sub.unsubscribe()
                except:
                    log("Sonos: Failed to unsubscribe: %s" % traceback.format_exc(), xbmc.LOGERROR)
                try:
                    # Make sure the thread is stopped even if unsubscribe failed
                    event_listener.stop()
                except:
                    log("Sonos: Failed to stop event listener: %s" % traceback.format_exc(), xbmc.LOGERROR)
                del sub

            sonosCtrl.close()
Пример #8
0
    def __init__(self):
        # Check if the auto update IP is enabled
        if not Settings.isAutoIpUpdateEnabled():
            return

        # Get the existing zone we are trying to set the IP Address for
        existingZone = Settings.getZoneName()

        # Nothing to do if there is no Zone name set
        if (existingZone is None) or (existingZone == ""):
            return

        # Set up the logging before using the Sonos Device
        SocoLogging.enable()

        try:
            sonos_devices = discover()
        except:
            log("AutoUpdateIPAddress: Exception when getting devices")
            log("AutoUpdateIPAddress: %s" % traceback.format_exc())
            sonos_devices = []

        if sonos_devices is None:
            log("AutoUpdateIPAddress: Failed to find any devices")
            sonos_devices = []

        ipaddresses = []

        # Check each of the devices found
        for device in sonos_devices:
            ip = device.ip_address
            log("AutoUpdateIPAddress: Getting info for IP address %s" % ip)

            playerInfo = None

            # Try and get the player info, if it fails then it is not a valid
            # player and we should continue to the next
            try:
                playerInfo = device.get_speaker_info()
            except:
                log("AutoUpdateIPAddress: IP address %s is not a valid player" % ip)
                log("AutoUpdateIPAddress: %s" % traceback.format_exc())
                continue

            # If player  info was found, then print it out
            if playerInfo is not None:
                # What is the name of the zone that this speaker is in?
                zone_name = playerInfo['zone_name']

                # Check the zone against the ones we are looking for
                if zone_name == existingZone:
                    # There could be multiple IP addressing in the same group
                    # so save them all
                    log("AutoUpdateIPAddress: IP address %s in zone %s" % (ip, existingZone))
                    ipaddresses.append(ip)

        # Check if there is an IP Address to set
        if len(ipaddresses) > 0:
            oldIp = Settings.getIPAddress()
            # Check if we already have a match to the existing IP Address
            matchesExisting = False
            for newIp in ipaddresses:
                if newIp == oldIp:
                    matchesExisting = True
                    break
            # If no match found - then set to the first IP Address
            if not matchesExisting:
                log("AutoUpdateIPAddress: Setting IP address to %s" % ipaddresses[0])
                Settings.setIPAddress(ipaddresses[0])
Пример #9
0
                                        log("SonosService: Currently playing artist = %s, album = %s, track = %s" % (track['artist'], track['album'], track['title']))

                                        # Get the album art if it is set (Default to the Sonos icon)
                                        albumArt = ICON
                                        if track['album_art'] != "":
                                            albumArt = track['album_art']

                                        # Gotham allows you to have a dialog without making a sound
                                        xbmcgui.Dialog().notification(track['artist'], track['title'], albumArt, Settings.getNotificationDisplayDuration(), False)
                                    else:
                                        sonosPopup = SonosPlayingPopup.createSonosPlayingPopup(track)
                                        sonosPopup.showPopup()
                                        del sonosPopup
                        except:
                            # Connection failure - may just be a network glitch - so don't exit
                            log("SonosService: Error from speaker %s" % Settings.getIPAddress())
                            log("SonosService: %s" % traceback.format_exc())

                        # No longer the first start
                        justStartedService = False

                    # Reset the timer for the next check
                    timeUntilNextCheck = Settings.getNotificationCheckFrequency() * Settings.getChecksPerSecond()

                # Increment the timer and sleep for a second before the next check
                xbmc.sleep(1000 / Settings.getChecksPerSecond())
                timeUntilNextCheck = timeUntilNextCheck - 1

            redirectVolume.cleanup()
            del redirectVolume
            del volumeLink