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'): sonos.next() print_current_track_info(sonos) elif (cmd == 'previous'): sonos.previous() print_current_track_info(sonos) 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")
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'): print(sonos.pause()) elif (cmd == 'stop'): print(sonos.stop()) elif (cmd == 'next'): print(sonos.next()) elif (cmd == 'previous'): print(sonos.previous()) elif (cmd == 'current'): track = sonos.get_current_track_info() print('Current track: ' + track['artist'] + ' - ' + track['title'] + '. From album ' + track['album'] + '. This is track number ' + track['playlist_position'] + ' in the playlist. It is ' + track['duration'] + ' minutes long.') elif (cmd == 'volume'): if (len(sys.argv) > 3): operator = sys.argv[3].lower() adjust_volume(sonos, operator) else: print(sonos.volume) else: print("Valid commands (with IP): info, play, pause, stop, next, previous, current, volume and partymode")
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'): print sonos.pause() elif (cmd == 'stop'): print sonos.stop() elif (cmd == 'next'): print sonos.next() elif (cmd == 'previous'): print sonos.previous() elif (cmd == 'current'): track = sonos.get_current_track_info() print 'Current track: ' + track['artist'] + ' - ' + track['title'] + '. From album ' + track['album'] + '. This is track number ' + track['playlist_position'] + ' in the playlist. It is ' + track['duration'] + ' minutes long.' elif (cmd == 'volume'): if (len(sys.argv) > 3): print sonos.volume(int(sys.argv[3])) else: print sonos.volume() else: print "Valid commands (with IP): info, play, pause, stop, next, previous, current, and partymode"
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'): 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() elif (cmd == 'queue'): print_queue() elif (cmd == 'volume'): if (len(sys.argv) > 3): operator = sys.argv[3].lower() adjust_volume(sonos, operator) else: print(sonos.volume) else: print("Valid commands (with IP): info, play, pause, stop, next, previous, current, volume and partymode")
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'): print sonos.pause() elif (cmd == 'stop'): print sonos.stop() elif (cmd == 'next'): print sonos.next() elif (cmd == 'previous'): print sonos.previous() elif (cmd == 'get_current_track_info'): print sonos.get_current_track_info() elif (cmd == 'add_to_queue'): print sonos.add_to_queue(sys.argv[3].lower()) elif (cmd == 'mute'): print sonos.mute() elif (cmd == 'get_queue'): print sonos.get_queue() elif (cmd == 'testing'): print sonos.testing() elif (cmd == 'volume'): if (len(sys.argv) > 3): print sonos.volume(sys.argv[3])