Esempio n. 1
0
        protected async override Task LoadImage()
        {
            var diAlbumCover = new DirectoryInfo(HurricaneSettings.Instance.CoverDirectory);

            Image = MusicCoverManager.GetSoundCloudImage(this, diAlbumCover, HurricaneSettings.Instance.Config.DownloadAlbumCoverQuality, HurricaneSettings.Instance.Config.LoadAlbumCoverFromInternet);

            if (Image == null)
            {
                Image = MusicCoverManager.GetImage(this, diAlbumCover);
            }

            if (Image == null && HurricaneSettings.Instance.Config.LoadAlbumCoverFromInternet)
            {
                try
                {
                    if (!string.IsNullOrEmpty(ArtworkUrl))
                    {
                        Image = await SoundCloudApi.LoadBitmapImage(this, HurricaneSettings.Instance.Config.DownloadAlbumCoverQuality, diAlbumCover);
                    }
                    if (Image == null)
                    {
                        Image = await MusicCoverManager.LoadCoverFromWeb(this, diAlbumCover, Uploader != Artist).ConfigureAwait(false);
                    }
                }
                catch (WebException)
                {
                    //Happens, doesn't matter
                }
            }
        }
Esempio n. 2
0
 public void Initialize()
 {
     ValidateConfiguration();
     SoundCloudApiUnAuthenticated = SoundCloudApi.CreateClient(TestSettings.ClientId);
     PasswordCredentialsState     = new PasswordCredentialsState();
     SoundCloudApiAuthenticated   = SoundCloudApi.CreateClient(TestSettings.ClientId, TestSettings.ClientSecret, TestSettings.UserName, TestSettings.Password, PasswordCredentialsState);
 }
Esempio n. 3
0
        public static BitmapImage GetSoundCloudImage(SoundCloudTrack track, DirectoryInfo di, ImageQuality quality, bool checkQuality)
        {
            string name = string.Format("{0}_{1}.jpg", track.SoundCloudID, SoundCloudApi.GetQualityModifier(quality));

            if (di.Exists)
            {
                return(di.GetFiles("*.jpg").Where(item => !checkQuality || item.Name.ToLower() == name).Select(item => new BitmapImage(new Uri(item.FullName))).FirstOrDefault());
            }
            return(null);
        }
Esempio n. 4
0
        protected async override Task LoadImage(DirectoryInfo albumCoverDirectory)
        {
            if (albumCoverDirectory.Exists)
            {
                var regex =
                    new Regex(HurricaneSettings.Instance.Config.LoadAlbumCoverFromInternet
                        ? string.Format("^{0}_{1}.", SoundCloudID,
                                        SoundCloudApi.GetQualityModifier(HurricaneSettings.Instance.Config.DownloadAlbumCoverQuality))
                        : string.Format("^{0}_", SoundCloudID));

                var imageFile = albumCoverDirectory.GetFiles().FirstOrDefault(item => regex.IsMatch(item.Name.ToLower()));
                if (imageFile != null)
                {
                    Image = new BitmapImage(new Uri(imageFile.FullName));
                    return;
                }

                Image = MusicCoverManager.GetAlbumImage(this, albumCoverDirectory);
                if (Image != null)
                {
                    return;
                }
            }


            if (HurricaneSettings.Instance.Config.LoadAlbumCoverFromInternet)
            {
                try
                {
                    if (!string.IsNullOrEmpty(ArtworkUrl))
                    {
                        Image = await SoundCloudApi.LoadBitmapImage(this, HurricaneSettings.Instance.Config.DownloadAlbumCoverQuality, albumCoverDirectory);

                        if (Image != null)
                        {
                            return;
                        }
                    }

                    Image = await MusicCoverManager.LoadCoverFromWeb(this, albumCoverDirectory, Uploader != Artist);
                }
                catch (WebException)
                {
                    //Happens, doesn't matter
                }
            }
        }
Esempio n. 5
0
        public void TestGetUserWithOAuthRequestForceRefresh()
        {
            SoundCloudApiAuthenticated.User().Get();

            var token = PasswordCredentialsState.Load();

            token.ExpiresIn = 1;
            // Override the usual hour long session soundcloud sends back

            while (!token.HasExpired())
            {
                Thread.Sleep(100);
            }
            PasswordCredentialsState.Save(token);

            SoundCloudApiAuthenticated = SoundCloudApi.CreateClient(TestSettings.ClientId, TestSettings.ClientSecret, PasswordCredentialsState);
            var user = SoundCloudApiAuthenticated.User().Get();

            Assert.IsNotEmpty(user.Username);
        }