def run(self): discover = SonosDiscovery() speakers = [] prev_found = [] prev_known = set() def call_callback(*args): self.callback(speakers) while True: self.interrupted = False try: found = discover.get_speaker_ips() except Exception as e: print e sleep(60) continue known = set(prev_found + found) if known != prev_known: speakers = [SoCo(ip) for ip in known] for sonos in speakers: sonos.name = sonos.get_speaker_info()['zone_name'] speakers.sort(key=lambda o: o.name) if not self.interrupted: Clock.schedule_once(call_callback) sleep(60) else: sleep(60) prev_known = known prev_found = found
def main(): sd = SonosDiscovery() speakers = sd.get_speaker_ips() if not speakers: print 'no speakers found, exiting.' return soco = SoCo(speakers[0]) # get a plugin by name (eg from a config file) myplugin = SoCoPlugin.from_name('soco.plugins.example.ExamplePlugin', soco, 'some user') # do something with your plugin print 'Testing', myplugin.name myplugin.music_plugin_play() time.sleep(5) # create a plugin by normal instantiation from soco.plugins.example import ExamplePlugin # create a new plugin, pass the soco instance to it myplugin = ExamplePlugin(soco, 'a user') print 'Testing', myplugin.name # do something with your plugin myplugin.music_plugin_stop()
def __init__(self): self.whole_house = [] sonos = SonosDiscovery() all_speakers = sonos.get_speaker_ips() for i in all_speakers: sonos = SoCo( i) result = sonos.get_speaker_info() self.whole_house.append(sonos)
def refresh_speaker_info(): sd = SonosDiscovery() possible_matches = sd.get_speaker_ips() speaker_info = {} for ip in possible_matches: s = SoCo(ip) try: speaker_info[ip] = s.get_speaker_info() except Exception, e: speaker_info[ip] = {}
class SonosForPandora(object): rpandora = None sonos = None def __init__(self): self.rpandora = RussPandora() self.sonos = SonosDiscovery() logging.info('found the following sonos servers : ' + ','.join(self.sonos.get_speaker_ips())) def playStation(self, stationNameLike, onSpeakerLike): LCDScreen.updateStatus("Pandora", "Loading music") stationId = self.rpandora.getIdForStation(stationNameLike) stationName = self.rpandora.getNameForStation(stationNameLike) LCDScreen.updateStatus("Pl: %s" % stationName, "On %s" % onSpeakerLike ) for speakerIp in self.sonos.get_speaker_ips(): try: sonosSpeaker = SoCo(str(speakerIp)) all_info = sonosSpeaker.get_speaker_info() if onSpeakerLike in all_info['zone_name'] : logging.info("Playing on speaker %s" % str(speakerIp)) sonosSpeaker.play_uri("pndrradio:%s" % str(stationId), '') LCDScreen.updateStatus("Pl: %s" % stationName, "On %s" % all_info['zone_name'] ) else: logging.info('Skipping player "%s"' % all_info['zone_name']) except: logging.error('Failed calling %s' % speakerIp) def stopPlaying(self): for speakerIp in self.sonos.get_speaker_ips(): sonosSpeaker = SoCo(speakerIp) all_info = sonosSpeaker.get_speaker_info() for item in all_info: logging.info("Stopping for speaker %s: %s" % (item, all_info[item])) sonos.stop() LCDScreen.updateStatus("Sonos" , "Music Stopped" ) def listAll(self): for speakerIp in self.sonos.get_speaker_ips(): logging.info("********* %s ***********" % str(speakerIp)) sonosSpeaker = SoCo(speakerIp) all_info = sonosSpeaker.get_speaker_info() for item in all_info: logging.info(" %s: %s" % (item, all_info[item])) logging.info('co-ordinator = ' + str(sonosSpeaker.get_group_coordinator(all_info['zone_name'], True))) logging.info("****************************" )
def connect(self): ips = [] while (len(ips) == 0): print "No Sonos found" sonos_devices = SonosDiscovery() ips = sonos_devices.get_speaker_ips() print "Found {0} device(s)".format(len(ips)) for ip in ips: self._device = SoCo(ip) zone_name = self._device.get_speaker_info()['zone_name'] print "IP of {0} is {1}".format(zone_name, ip)
def __init__(self): self.logger = logging.getLogger(__name__) self.logger.setLevel(logging.DEBUG) fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' fmt = logging.Formatter(fmt) # Configuring logging to file # Currently logs everything DEBUG and above logfile = logging.FileHandler('clock.log') logfile.setLevel(logging.DEBUG) logfile.setFormatter(fmt) self.logger.addHandler(logfile) # Configuring logging to stdout # Currently logs everything INFO and above:w stderr_handle = logging.StreamHandler() stderr_handle.setLevel(logging.INFO) stderr_handle.setFormatter(fmt) self.logger.addHandler(stderr_handle) self.logger.info('Starting log...') # Time variables self._then = '' # Player variables self._ZONE_IPS = [] self.logger.info('Searching for zones...') disc = SonosDiscovery() self.household = {} self.logger.info('Building household tree...') for ip in disc.get_speaker_ips(): device = SoCo(ip) try: zone = device.get_speaker_info()['zone_name'] if zone != None: if self.household.has_key(zone): self.household[zone].append(ip) else: self.household[zone] = [] self.household[zone].append(ip) except ValueError: msg = 'Zone with no name at '+ip+', possibly a bridge' self.logger.error(msg) continue
def __init__(self): self.logger = logging.getLogger(__name__) self.logger.setLevel(logging.DEBUG) fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' fmt = logging.Formatter(fmt) # Configuring logging to file # Currently logs everything DEBUG and above logfile = logging.FileHandler('clock.log') logfile.setLevel(logging.DEBUG) logfile.setFormatter(fmt) self.logger.addHandler(logfile) # Configuring logging to stdout # Currently logs everything INFO and above:w stderr_handle = logging.StreamHandler() stderr_handle.setLevel(logging.INFO) stderr_handle.setFormatter(fmt) self.logger.addHandler(stderr_handle) self.logger.info('Starting log...') # Time variables self._then = '' # Player variables self._ZONE_IPS = [] self.logger.info('Searching for zones...') disc = SonosDiscovery() self.household = {} self.logger.info('Building household tree...') for ip in disc.get_speaker_ips(): device = SoCo(ip) try: zone = device.get_speaker_info()['zone_name'] if zone != None: if self.household.has_key(zone): self.household[zone].append(ip) else: self.household[zone] = [] self.household[zone].append(ip) except ValueError: msg = 'Zone with no name at ' + ip + ', possibly a bridge' self.logger.error(msg) continue
def __init__(self): # Time variables self._then = '' # Player variables self._ZONE_IPS = [] disc = SonosDiscovery() self.household = {} for ip in disc.get_speaker_ips(): device = SoCo(ip) try: zone = device.get_speaker_info()['zone_name'] if zone != None: if self.household.has_key(zone): self.household[zone].append(ip) else: self.household[zone] = [] self.household[zone].append(ip) except ValueError: continue
def callback(d): data = json.loads(d) url = data['url'] sonos_devices = SonosDiscovery() ips = sonos_devices.get_speaker_ips() master = SoCo(ips[0]) masteruid = master.get_speaker_info()['uid'] for ip in ips: if not (ip == master.speaker_ip): slave = SoCo(ip) ret = slave.join(masteruid) oldvol = master.volume master.volume = 60 master.play_uri(url) playing = True while playing: if master.get_current_transport_info()['current_transport_state'] == 'STOPPED': playing = False master.volume = oldvol for ip in ips: if not (ip == master.speaker_ip): slave = SoCo(ip) slave.unjoin()
return factor if __name__ == '__main__': if (len(sys.argv) > 4 or len(sys.argv) < 3): print("Usage: sonoshell.py [speaker's IP|all] [cmd]") print("") print("Valid commands (with IP): info, play, pause, stop, next, previous, current, volume and partymode") print("Valid commands (with 'all'): list_ips") sys.exit() speaker_spec = sys.argv[1] cmd = sys.argv[2].lower() if speaker_spec == "all": sonos = SonosDiscovery() if (cmd == 'list_ips'): print('\n'.join(sonos.get_speaker_ips())) else: print("Valid commands (with 'all'): list_ips") else: sonos = SoCo(speaker_spec) if (cmd == 'partymode'): print(sonos.partymode()) elif (cmd == 'info'): all_info = sonos.get_speaker_info() for item in all_info: print("%s: %s" % (item, all_info[item])) elif (cmd == 'play'): print(sonos.play()) elif (cmd == 'pause'):
def main(): if (len(sys.argv) > 4 or len(sys.argv) < 3): print("Usage: sonoshell.py [speaker's IP|all] [cmd]") print("") print("Valid commands (with IP): info, state, play, pause, stop, next, previous, current, queue, volume and partymode") print("Valid commands (with 'all'): list_ips") sys.exit() speaker_spec = sys.argv[1] cmd = sys.argv[2].lower() if speaker_spec == "all": sonos = SonosDiscovery() if (cmd == 'list_ips'): print('\n'.join(sonos.get_speaker_ips())) else: print("Valid commands (with 'all'): list_ips") else: sonos = SoCo(speaker_spec) if (cmd == 'partymode'): print(sonos.partymode()) elif (cmd == 'info'): all_info = sonos.get_speaker_info() for item in all_info: print("%s: %s" % (item, all_info[item])) elif (cmd == 'play'): if len(sys.argv) > 3: play_index(sonos, sys.argv[3]) else: sonos.play() print_current_track_info(sonos) elif (cmd == 'pause'): print(sonos.pause()) elif (cmd == 'stop'): print(sonos.stop()) elif (cmd == 'next'): print(sonos.next()) elif (cmd == 'previous'): print(sonos.previous()) elif (cmd == 'current'): print_current_track_info(sonos) elif (cmd == 'queue'): print_queue(sonos) elif (cmd == 'volume'): if (len(sys.argv) > 3): operator = sys.argv[3].lower() adjust_volume(sonos, operator) else: print(sonos.volume) elif (cmd == 'state'): print(sonos.get_current_transport_info()['current_transport_state']) else: print("Valid commands (with IP): info, state, play, pause, stop, next, previous, current, volume and partymode")
def find_controllers(): dev = SonosDiscovery() for ip in dev.get_speaker_ips(): s = SoCo(ip) zone = s.get_speaker_info()['zone_name'] p("{}: {}".format(zone, ip))
from soco import SoCo from soco import SonosDiscovery if __name__ == '__main__': if (len(sys.argv) < 3): print "Usage: sonoshell.py [speaker's IP|all] [cmd] [option]" print "" print "Valid commands (with IP): info, play, pause, stop, next, previous, current, volume, and partymode" print "Valid commands (with 'all'): list_ips" sys.exit() speaker_spec = sys.argv[1] cmd = sys.argv[2].lower() if speaker_spec == "all": sonos = SonosDiscovery() if (cmd == 'list_ips'): print '\n'.join(sonos.get_speaker_ips()) else: print "Valid commands (with 'all'): list_ips" else: sonos = SoCo(speaker_spec) if (cmd == 'partymode'): print sonos.partymode() elif (cmd == 'info'): all_info = sonos.get_speaker_info() for item in all_info: print "%s: %s" % (item, all_info[item]) elif (cmd == 'play'): print sonos.play() elif (cmd == 'pause'):
def get_devices(): ips = set() for ip in SonosDiscovery().get_speaker_ips(): ips.add(ip) return [SoCo(ip) for ip in ips]
from soco import SoCo from soco import SonosDiscovery if __name__ == '__main__': if (len(sys.argv) == 2): print "Usage: sonoshell.py [speaker's IP|all] [cmd]" print "" print "Valid commands (with IP): info, play, pause, stop, next, previous, current, and partymode" print "Valid commands (with 'all'): list_ips" sys.exit() speaker_spec = sys.argv[1] cmd = sys.argv[2].lower() if speaker_spec == "all": sonos = SonosDiscovery() if (cmd == 'list_ips'): print '\n'.join(sonos.get_speaker_ips()) else: print "Valid commands (with 'all'): list_ips" else: sonos = SoCo(speaker_spec) if (cmd == 'partymode'): print sonos.partymode() elif (cmd == 'info'): all_info = sonos.get_speaker_info() for item in all_info: print "%s: %s" % (item, all_info[item]) elif (cmd == 'play'): print sonos.play() elif (cmd == 'pause'):
from soco import SoCo from soco import SonosDiscovery if __name__ == '__main__': sonos_devices = SonosDiscovery() for ip in sonos_devices.get_speaker_ips(): device = SoCo(ip) zone_name = device.get_speaker_info()['zone_name'] print "IP of %s is %s" % (zone_name, ip)
#!/usr/bin/env python import sys from soco import SoCo from soco import SonosDiscovery if __name__ == "__main__": speaker_spec = sys.argv[1] cmd = sys.argv[2].lower() arg = sys.argv[3] if len(sys.argv) > 3 else None if speaker_spec == "all": sonos = SonosDiscovery() if cmd == "list_ips": print "\n".join(sonos.get_speaker_ips()) else: print "Valid commands (with 'all'): list_ips" else: sonos = SoCo(speaker_spec) if cmd == "partymode": print sonos.partymode() elif cmd == "info": all_info = sonos.get_speaker_info() for item in all_info: print "%s: %s" % (item, all_info[item]) elif cmd == "play": print sonos.play()
colorama.deinit() if __name__ == '__main__': if (len(sys.argv) > 4 or len(sys.argv) < 3): print("Usage: sonoshell.py [speaker's IP|all] [cmd]") print("") print("Valid commands (with IP): info, play, pause, stop, next, previous, current, queue, volume and partymode") print("Valid commands (with 'all'): list_ips") sys.exit() speaker_spec = sys.argv[1] cmd = sys.argv[2].lower() if speaker_spec == "all": sonos = SonosDiscovery() if (cmd == 'list_ips'): print('\n'.join(sonos.get_speaker_ips())) else: print("Valid commands (with 'all'): list_ips") else: sonos = SoCo(speaker_spec) if (cmd == 'partymode'): print(sonos.partymode()) elif (cmd == 'info'): all_info = sonos.get_speaker_info() for item in all_info: print("%s: %s" % (item, all_info[item])) elif (cmd == 'play'): print(sonos.play()) elif (cmd == 'pause'):
#!/usr/bin/env python #should be used with vkey_sketch3.ino from time import sleep from soco import SoCo from soco import SonosDiscovery import serial #####ser = serial.Serial("/dev/ttyACM0", 9600, timeout=1) #ser = serial.Serial("/dev/ttyACM0", 9600, timeout=0.5) #ser = serial.Serial("COM19", 9600, timeout=0.5) DEBUG = 1 sonos_devices = SonosDiscovery() speakers = {SoCo(ip).player_name: SoCo(ip) for ip in sonos_devices.get_speaker_ips()} # As far as I can tell player_name == get_speaker_info()['zone_name] for name,speaker in speakers.items(): a = speaker.get_current_track_info()['artist'] #print "player_name: {}; ip: {}; zone name: {}; artist: {}".format(name, speaker.speaker_ip, speaker.get_speaker_info()['zone_name'], a) print "player_name: {}; ip: {}; artist: {}".format(name, speaker.speaker_ip, a) # using the presence of an artist to decide that is the master speaker - seems to work if a: master = speaker print "\nmaster speaker = {}: {}".format(master.player_name,master.speaker_ip)
def __init__(self): self.rpandora = RussPandora() self.sonos = SonosDiscovery() logging.info('found the following sonos servers : ' + ','.join(self.sonos.get_speaker_ips()))