public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, IEncryptionManager encryption)
            : base(applicationPaths, xmlSerializer)
        {
            Instance    = this;
            _encryption = encryption;

            var username = Instance.Configuration.Username;
            var password = Instance.Configuration.PwData;

            var creds = new SoundCloudCredentials("78fd88dde7ebf8fdcad08106f6d56ab6",
                                                  "ef6b3dbe724eff1d03298c2e787a69bd");

            if (username != null && password != null)
            {
                creds = new SoundCloudCredentials("78fd88dde7ebf8fdcad08106f6d56ab6",
                                                  "ef6b3dbe724eff1d03298c2e787a69bd", username, _encryption.DecryptString(Instance.Configuration.PwData));
            }

            _SoundCloudClient = new SoundCloudClient(creds);

            if (username != null && password != null)
            {
                _SoundCloudClient.Authenticate();
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //fill credentials
            SoundCloudCredentials credentials = new SoundCloudCredentials(ClientId, ClientSecret, Username, Password);
            //create client
            SoundCloudClient client = new SoundCloudClient(credentials);
            //login to soundcloud
            SoundCloudAccessToken token = client.Authenticate();

            //fetch some data
            if (client.IsAuthenticated)
            {
                //Fetch current user info
                var mySelf = User.Me();
                //search for tracks
                string searchFor = "electro swing";
                //execute search
                List <Track> searchResults = Track.Search(searchFor, null, Filter.All, "", "", null, null, null, null, DateTime.MinValue, DateTime.Now, null, null, null);
                //iterate in tracks and fetch details again
                foreach (int trackId in searchResults.Select(track => track.Id))
                {
                    Track track = Track.GetTrack(trackId);
                    //here you can play a track or do something else ;)
                }
            }
            //wait for user input
            Console.ReadLine();
        }
Exemple #3
0
        public void AttemptLogin(bool createNotificationOnFailure)
        {
            var username = Instance.Configuration.Username;
            var password = _encryption.DecryptString(Instance.Configuration.PwData);

            if (!string.IsNullOrWhiteSpace(username) && !string.IsNullOrWhiteSpace(password))
            {
                try
                {
                    _soundCloudClient.Authenticate(username, password);
                }
                catch (Exception ex)
                {
                    var msg = "Unable to login to SoundCloud. Please check username and password.";

                    //if (!string.IsNullOrWhiteSpace(ex.ResponseBody))
                    //{
                    //    msg = string.Format("{0} ({1})", msg, ex.ResponseBody);
                    //}

                    _logger.ErrorException(msg, ex);

                    if (createNotificationOnFailure)
                    {
                        var request = new NotificationRequest
                        {
                            Description    = msg,
                            Date           = DateTime.Now,
                            Level          = NotificationLevel.Error,
                            SendToUserMode = SendToUserType.Admins
                        };

                        _notificationManager.SendNotification(request, CancellationToken.None);
                    }
                    else
                    {
                        msg = string.Format("{0}\n\nAttention: You need to wait up to 3 minutes before retrying!", msg);
                        throw new Exception(msg);
                    }
                }
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var username = this.Username.Text;
            var passwrod = this.Password.Password;

            new Thread(() =>
            {
                var credentials             = new SoundCloudCredentials(ClientId, ClientSecret, username, passwrod);
                var client                  = new SoundCloudClient(credentials);
                SoundCloudAccessToken token = null;

                try
                {
                    token = client.Authenticate();
                }
                catch (Exception)
                {
                    MessageBox.Show("login failed.");
                    return;
                }
                var downloader = new Downloader(ClientId, token.AccessToken);

                //fetch some data
                if (client.IsAuthenticated)
                {
                    //Fetch current user info
                    var mySelf    = User.Me();
                    var clientID  = client.getClientID();
                    var trackList = new List <Track>();
                    var i         = 1;
                    var limit     = 200;

                    var favorites = User.Me().GetFavorites(limit, 1);

                    while (favorites.NextHref != null)
                    {
                        foreach (var favorite in favorites.Tracks)
                        {
                            var track = Track.GetTrack(favorite.Id);
                            if (downloader.DownloadMusicWithTrackId(track))
                            {
                                ListView1.Dispatcher.Invoke(
                                    new Action(() =>
                                {
                                    _likeCollection.Add(new Like()
                                    {
                                        Index = i++, Title = track.Title
                                    });
                                }));
                            }
                        }

                        favorites = JsonSerializer.Deserialize <Favorite>(new WebClient()
                        {
                            Encoding = new UTF8Encoding()
                        }.DownloadString(favorites.NextHref));
                    }

                    MessageBox.Show("download successfully finished.");
                }
            }).Start();
        }