
import soco, sys

speakers = list(soco.discover())


state = speakers[0].get_current_transport_info()['current_transport_state']

if state == 'PLAYING':
    if len(sys.argv) > 1 and sys.argv[1] == "1":
        speakers[0].stop()
        print("")
    else:
        track = speakers[0].get_current_track_info()
        print(" " + track['title'] + " - " + track['artist'])
else:
    if len(sys.argv) > 1 and sys.argv[1] == "1":
        speakers[0].play()
        track = speakers[0].get_current_track_info()
        print(" " + track['title'] + " - " + track['artist'])
    else:
        print("")


import soco, sys

speakers = list(soco.discover())

if len(speakers) > 0:
    state = speakers[0].get_current_transport_info()['current_transport_state']

    if state == 'PLAYING':
        if len(sys.argv) > 1 and sys.argv[1] == "1":
            speakers[0].stop()
            print("")
        else:
            track = speakers[0].get_current_track_info()
            print(" " + track['title'] + " - " + track['artist'])
    else:
        if len(sys.argv) > 1 and sys.argv[1] == "1":
            speakers[0].play()
            track = speakers[0].get_current_track_info()
            print(" " + track['title'] + " - " + track['artist'])
        else:
            print("")

Remove script crash when no sonos is found
Remove script crash when no sonos is found

  
  import soco, sys
  
  speakers = list(soco.discover())
  
+ if len(speakers) > 0:
+     state = speakers[0].get_current_transport_info()['current_transport_state']
  
- state = speakers[0].get_current_transport_info()['current_transport_state']
+     if state == 'PLAYING':
+         if len(sys.argv) > 1 and sys.argv[1] == "1":
+             speakers[0].stop()
+             print("")
+         else:
+             track = speakers[0].get_current_track_info()
+             print(" " + track['title'] + " - " + track['artist'])
+     else:
+         if len(sys.argv) > 1 and sys.argv[1] == "1":
+             speakers[0].play()
+             track = speakers[0].get_current_track_info()
+             print(" " + track['title'] + " - " + track['artist'])
+         else:
+             print("")
  
- if state == 'PLAYING':
-     if len(sys.argv) > 1 and sys.argv[1] == "1":
-         speakers[0].stop()
-         print("")
-     else:
-         track = speakers[0].get_current_track_info()
-         print(" " + track['title'] + " - " + track['artist'])
- else:
-     if len(sys.argv) > 1 and sys.argv[1] == "1":
-         speakers[0].play()
-         track = speakers[0].get_current_track_info()
-         print(" " + track['title'] + " - " + track['artist'])
-     else:
-         print("")
- 
Remove script crash when no sonos is found
## Code Before:

import soco, sys

speakers = list(soco.discover())


state = speakers[0].get_current_transport_info()['current_transport_state']

if state == 'PLAYING':
    if len(sys.argv) > 1 and sys.argv[1] == "1":
        speakers[0].stop()
        print("")
    else:
        track = speakers[0].get_current_track_info()
        print(" " + track['title'] + " - " + track['artist'])
else:
    if len(sys.argv) > 1 and sys.argv[1] == "1":
        speakers[0].play()
        track = speakers[0].get_current_track_info()
        print(" " + track['title'] + " - " + track['artist'])
    else:
        print("")

## Instruction:
Remove script crash when no sonos is found
## Code After:

import soco, sys

speakers = list(soco.discover())

if len(speakers) > 0:
    state = speakers[0].get_current_transport_info()['current_transport_state']

    if state == 'PLAYING':
        if len(sys.argv) > 1 and sys.argv[1] == "1":
            speakers[0].stop()
            print("")
        else:
            track = speakers[0].get_current_track_info()
            print(" " + track['title'] + " - " + track['artist'])
    else:
        if len(sys.argv) > 1 and sys.argv[1] == "1":
            speakers[0].play()
            track = speakers[0].get_current_track_info()
            print(" " + track['title'] + " - " + track['artist'])
        else:
            print("")
