示例#1
0
        public SpShell(AutoResetEvent aSpotifyEvent, string aUsername, string aPassword, string aBlob, bool aSelftest, ConsoleReader aReader, byte[] aAppKey)
        {
            iReader       = aReader;
            iSpotifyEvent = aSpotifyEvent;
            SpotifySessionConfig config = new SpotifySessionConfig();

            config.ApiVersion       = 12;
            config.CacheLocation    = aSelftest ? "" : "tmp";
            config.SettingsLocation = aSelftest ? "" : "tmp";
            config.ApplicationKey   = aAppKey;
            config.UserAgent        = "spshell#";
            config.Listener         = this;

            try
            {
                iSession = SpotifySession.Create(config);
            }
            catch (SpotifyException e)
            {
                Console.Error.WriteLine("Failed to create session: {0}", e.Message);
                throw;
            }

            iBrowser         = new Browser(iSession, this, aReader);
            iSearcher        = new Searcher(iSession, aReader);
            iTopLister       = new TopLister(iSession, aReader);
            iMessaging       = new Messaging(iSession, aReader, iBrowser);
            iStarManager     = new StarManager(iSession, aReader, iBrowser);
            iPlaylistManager = new PlaylistManager(iSession, aReader, iBrowser);

            iCommands = new ConsoleCommandDictionary(CmdDone)
            {
                { "log", CmdLog, "Enable/Disable logging to console (default off)" },
                { "logout", CmdLogout, "Logout and exit app" },
                { "exit", CmdLogout, "Logout and exit app" },
                { "quit", CmdLogout, "Logout and exit app" },
                { "browse", iBrowser.CmdBrowse, "Browse a Spotify URL" },
                { "search", iSearcher.CmdSearch, "Search" },
                { "whatsnew", iSearcher.CmdWhatsNew, "List new albums" },
                { "toplist", iTopLister.CmdTopList, "Browse toplists" },
                { "post", iMessaging.CmdPost, "Post track to a user's inbox" },
                { "inbox", iMessaging.CmdInbox, "View inbox" },
                { "star", iStarManager.CmdStar, "Star a track" },
                { "unstar", iStarManager.CmdUnstar, "Unstar a track" },
                { "starred", iStarManager.CmdStarred, "List all starred tracks" },
                { "playlists", iPlaylistManager.CmdPlaylists, "List playlists" },
                { "playlist", iPlaylistManager.CmdPlaylist, "List playlist contents" },
                { "set_autolink", iPlaylistManager.CmdSetAutolink, "Set autolinking state" },
                { "add_folder", iPlaylistManager.CmdAddFolder, "Add playlist folder" },
                { "update_subscriptions", iPlaylistManager.CmdUpdateSubscriptions, "Update playlist subscription info" },
                { "add", iPlaylistManager.CmdAddTrack, "Add track to playlist" },
                { "offline", iPlaylistManager.CmdPlaylistOffline, "Set offline mode for a playlist" },
            };
            iCommands.Add("help", iCommands.CmdHelp, "This help");

            try
            {
                if (aUsername == null)
                {
                    iSession.Relogin();
                    var reloginname = iSession.RememberedUser();
                    Console.Error.WriteLine("Trying to relogin as user {0}", reloginname);
                }
                else
                {
                    iSession.Login(aUsername, aPassword, true, aBlob);
                }
            }
            catch (SpotifyException e)
            {
                if (e.Error == SpotifyError.NoCredentials)
                {
                    Console.Error.WriteLine("No stored credentials");
                    throw;
                }
            }
        }
 public Callbacks(PlaylistManager aPlaylistManager)
 {
     iPlaylistManager = aPlaylistManager;
 }