func main() { username := flag.String("username", "", "spotify username") password := flag.String("password", "", "spotify password") appkey := flag.String("appkey", "./spotify_appkey.key", "spotify appkey file path") blobPath := flag.String("blobPath", "", "path to saved blob") devicename := flag.String("devicename", defaultdevicename, "name of device") flag.Parse() var sController *spotcontrol.SpircController var err error if *username != "" && *password != "" { sController, err = spotcontrol.Login(*username, *password, *appkey, *devicename) } else if *blobPath != "" { if _, err = os.Stat(*blobPath); os.IsNotExist(err) { sController, err = spotcontrol.LoginDiscovery(*blobPath, *appkey, *devicename) } else { sController, err = spotcontrol.LoginBlobFile(*blobPath, *appkey, *devicename) } } else { fmt.Println("need to supply a username and password or a blob file path") fmt.Println("./spirccontroller --blobPath ./path/to/blob") fmt.Println("or") fmt.Println("./spirccontroller --username SPOTIFY_USERNAME --password SPOTIFY_PASSWORD") return } if err != nil { fmt.Println("Error logging in: ", err) return } reader := bufio.NewReader(os.Stdin) var ident string printHelp() for { fmt.Print("Enter a command: ") text, _ := reader.ReadString('\n') cmds := strings.Split(strings.TrimSpace(text), " ") switch { case cmds[0] == "load": ident = getDevice(sController, ident, reader) if ident != "" { sController.LoadTrack(ident, cmds[1:]) } case cmds[0] == "hello": sController.SendHello() case cmds[0] == "play": ident = getDevice(sController, ident, reader) if ident != "" { sController.SendPlay(ident) } case cmds[0] == "pause": ident = getDevice(sController, ident, reader) if ident != "" { sController.SendPause(ident) } case cmds[0] == "devices": ident = chooseDevice(sController, reader) case cmds[0] == "mdns": addMdns(sController, reader) case cmds[0] == "help": printHelp() } } }