static void Main(string[] args) { string username = args.Length > 0 ? args[0] : null; string blob = args.Length > 1 ? args[1] : null; string password = null; byte[] appkey; bool selftest = args.Length > 2 ? args[2] == "selftest" : false; try { appkey = File.ReadAllBytes("spotify_appkey.key"); } catch (IOException) { Console.WriteLine("Please download your binary app key from Spotify and put it in"); Console.WriteLine("the working directory as 'spotify_appkey.key'. See here:"); Console.WriteLine("https://developer.spotify.com/technologies/libspotify/keys/"); Console.WriteLine(""); Console.WriteLine("Press any key..."); Console.ReadKey(); return; } using (var consoleReader = new ConsoleReader()) { WaitHandle[] handles = new WaitHandle[2]; AutoResetEvent spotifyEvent; handles[0] = spotifyEvent = new AutoResetEvent(false); handles[1] = consoleReader.InputReady; Console.WriteLine("Using libspotify {0}", Spotify.BuildId()); if (username == null) { Console.Write("Username (press enter to login with stored credentials): "); username = (Console.ReadLine() ?? "").TrimEnd(); if (username == "") { username = null; } } if (username != null && blob == null) { Console.WriteLine("Password: "******"").TrimEnd(); } using (SpShell shell = new SpShell(spotifyEvent, username, password, blob, selftest, consoleReader, appkey)) { //consoleReader.RequestInput("> "); int next_timeout = 0; while (!shell.IsFinished) { int ev = WaitHandle.WaitAny(handles, next_timeout != 0 ? next_timeout : Timeout.Infinite); switch (ev) { case 0: case WaitHandle.WaitTimeout: do { shell.ProcessEvents(ref next_timeout); } while (next_timeout == 0); if (selftest) { // TODO: TestProcess } break; case 1: shell.ProcessConsoleInput(consoleReader.GetInput()); break; } } Console.WriteLine("Logged out"); } Console.WriteLine("Exiting..."); } }