Example #1
0
        private void DownloadSpotifyAlbumArtwork(string albumId)
        {
            string artworkDirectory = @Application.StartupPath + @"\SpotifyArtwork";
            string artworkImagePath = string.Format(CultureInfo.InvariantCulture, @"{0}\{1}.jpg", artworkDirectory, albumId);

            if (!Directory.Exists(artworkDirectory))
            {
                Directory.CreateDirectory(artworkDirectory);
            }

            FileInfo fileInfo = new FileInfo(artworkImagePath);

            if (fileInfo.Exists && fileInfo.Length > 0)
            {
                fileInfo.CopyTo(this.DefaultArtworkFilePath, true);
            }
            else
            {
                this.SaveBlankImage();

                using (WebClientWithShortTimeout webClient = new WebClientWithShortTimeout())
                {
                    try
                    {
                        webClient.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko";
                        var downloadedJson = webClient.DownloadString(string.Format(CultureInfo.InvariantCulture, "https://embed.spotify.com/oembed/?url=spotify:album:{0}", albumId));

                        if (!string.IsNullOrEmpty(downloadedJson))
                        {
                            dynamic jsonSummary = SimpleJson.DeserializeObject(downloadedJson);

                            string imageUrl = jsonSummary.thumbnail_url.ToString().Replace("cover", string.Format(CultureInfo.InvariantCulture, "{0}", (int)Globals.ArtworkResolution));

                            if (Globals.KeepSpotifyAlbumArtwork)
                            {
                                webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadSpotifyFileCompleted);
                                webClient.DownloadFileAsync(new Uri(imageUrl), artworkImagePath, artworkImagePath);
                            }
                            else
                            {
                                webClient.DownloadFileAsync(new Uri(imageUrl), this.DefaultArtworkFilePath);
                            }

                            this.SavedBlankImage = false;
                        }
                    }
                    catch (WebException)
                    {
                        this.SaveBlankImage();
                    }
                }
            }
        }
Example #2
0
        private void DownloadSpotifyAlbumArtwork(dynamic jsonSummary)
        {
            string albumId = jsonSummary.id;

            string artworkDirectory = @Application.StartupPath + @"\SpotifyArtwork";
            string artworkImagePath = string.Format(CultureInfo.InvariantCulture, @"{0}\{1}.jpg", artworkDirectory, albumId);

            if (!Directory.Exists(artworkDirectory))
            {
                Directory.CreateDirectory(artworkDirectory);
            }

            FileInfo fileInfo = new FileInfo(artworkImagePath);

            if (fileInfo.Exists && fileInfo.Length > 0)
            {
                fileInfo.CopyTo(this.DefaultArtworkFilePath, true);

                this.SavedBlankImage = false;
            }
            else
            {
                using (WebClientWithShortTimeout webClient = new WebClientWithShortTimeout())
                {
                    try
                    {
                        Uri imageUrl = SelectAlbumArtworkSizeToDownload(jsonSummary);

                        webClient.Headers.Add("User-Agent", "Snip/" + AssemblyInformation.AssemblyVersion);

                        if (Globals.KeepSpotifyAlbumArtwork)
                        {
                            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadSpotifyFileCompleted);
                            webClient.DownloadFileAsync(imageUrl, artworkImagePath, artworkImagePath);
                        }
                        else
                        {
                            webClient.DownloadFileAsync(imageUrl, this.DefaultArtworkFilePath);
                        }

                        this.SavedBlankImage = false;
                    }
                    catch (WebException)
                    {
                        this.SaveBlankImage();
                    }
                }
            }
        }
Example #3
0
        private void DownloadGPMDPAlbumArtwork(string albumArtAddress)
        {
            using (WebClientWithShortTimeout webClient = new WebClientWithShortTimeout())
            {
                try
                {
                    Uri imageUrl = new Uri(albumArtAddress);

                    webClient.Headers.Add("User-Agent", "Snip/" + AssemblyInformation.AssemblyVersion);

                    webClient.DownloadFileAsync(imageUrl, this.DefaultArtworkFilePath);

                    this.SavedBlankImage = false;
                }
                catch (WebException)
                {
                    this.SaveBlankImage();
                }
            }
        }
Example #4
0
File: Snip.cs Project: hahawer/Snip
        private void DownloadSpotifyAlbumArtwork(string albumId, int albumArtworkResolution, string savePath = null)
        {
            using (WebClientWithShortTimeout webClient = new WebClientWithShortTimeout())
            {
                try
                {
                    var json = webClient.DownloadString(string.Format(CultureInfo.InvariantCulture, "https://embed.spotify.com/oembed/?url=spotify:album:{0}", albumId));

                    dynamic jsonSummary = SimpleJson.DeserializeObject(json);

                    string imageUrl = jsonSummary.thumbnail_url.ToString().Replace("cover", string.Format(CultureInfo.InvariantCulture, "{0}", albumArtworkResolution));

                    if (savePath == null)
                    {
                        webClient.DownloadFileAsync(new Uri(imageUrl), this.defaultArtworkFile);
                    }
                    else
                    {
                        this.SaveBlankImage();

                        webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadSpotifyFileCompleted);
                        webClient.DownloadFileAsync(new Uri(imageUrl), savePath, savePath);
                    }
                }
                catch (WebException)
                {
                    this.SaveBlankImage();
                }
            }
        }
Example #5
0
        private void DownloadSpotifyAlbumArtwork(string albumId, int albumArtworkResolution, string savePath = null)
        {
            this.SaveBlankImage();

            using (WebClientWithShortTimeout webClient = new WebClientWithShortTimeout())
            {
                try
                {
                    webClient.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko";
                    var json = webClient.DownloadString(string.Format(CultureInfo.InvariantCulture, "https://embed.spotify.com/oembed/?url=spotify:album:{0}", albumId));

                    if (!string.IsNullOrEmpty(json))
                    {
                        dynamic jsonSummary = SimpleJson.DeserializeObject(json);

                        string imageUrl = jsonSummary.thumbnail_url.ToString().Replace("cover", string.Format(CultureInfo.InvariantCulture, "{0}", albumArtworkResolution));

                        this.SaveBlankImage();

                        if (savePath == null)
                        {
                            webClient.DownloadFileAsync(new Uri(imageUrl), this.DefaultArtworkFilePath);
                        }
                        else
                        {
                            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadSpotifyFileCompleted);
                            webClient.DownloadFileAsync(new Uri(imageUrl), savePath, savePath);
                        }
                    }
                }
                catch (WebException)
                {
                    this.SaveBlankImage();
                }
            }
        }
Example #6
0
        private void DownloadSpotifyAlbumArtwork(dynamic jsonSummary)
        {
            string albumId = jsonSummary.id.ToString();

            string artworkDirectory = @Application.StartupPath + @"\SpotifyArtwork";
            string artworkImagePath = string.Format(CultureInfo.InvariantCulture, @"{0}\{1}.jpg", artworkDirectory, albumId);

            if (!Directory.Exists(artworkDirectory))
            {
                Directory.CreateDirectory(artworkDirectory);
            }

            FileInfo fileInfo = new FileInfo(artworkImagePath);

            if (fileInfo.Exists && fileInfo.Length > 0)
            {
                fileInfo.CopyTo(this.DefaultArtworkFilePath, true);
            }
            else
            {
                this.SaveBlankImage();

                using (WebClientWithShortTimeout webClient = new WebClientWithShortTimeout())
                {
                    try
                    {
                        // This assumes that the Spotify image array will always have three results (which in all of my tests it has so far)
                        string imageUrl = string.Empty;

                        switch (Globals.ArtworkResolution)
                        {
                        case Globals.AlbumArtworkResolution.Large:
                            imageUrl = jsonSummary.images[0].url.ToString();
                            break;

                        case Globals.AlbumArtworkResolution.Medium:
                            imageUrl = jsonSummary.images[1].url.ToString();
                            break;

                        case Globals.AlbumArtworkResolution.Tiny:
                            imageUrl = jsonSummary.images[2].url.ToString();
                            break;

                        default:
                            imageUrl = jsonSummary.images[0].url.ToString();
                            break;
                        }

                        webClient.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko";

                        if (Globals.KeepSpotifyAlbumArtwork)
                        {
                            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadSpotifyFileCompleted);
                            webClient.DownloadFileAsync(new Uri(imageUrl), artworkImagePath, artworkImagePath);
                        }
                        else
                        {
                            webClient.DownloadFileAsync(new Uri(imageUrl), this.DefaultArtworkFilePath);
                        }

                        this.SavedBlankImage = false;
                    }
                    catch (WebException)
                    {
                        this.SaveBlankImage();
                    }
                }
            }
        }
Example #7
0
        private void DownloadSpotifyAlbumArtwork(string albumId)
        {
            string artworkDirectory = @Application.StartupPath + @"\SpotifyArtwork";
            string artworkImagePath = string.Format(CultureInfo.InvariantCulture, @"{0}\{1}.jpg", artworkDirectory, albumId);

            if (!Directory.Exists(artworkDirectory))
            {
                Directory.CreateDirectory(artworkDirectory);
            }

            FileInfo fileInfo = new FileInfo(artworkImagePath);

            if (fileInfo.Exists && fileInfo.Length > 0)
            {
                fileInfo.CopyTo(this.DefaultArtworkFilePath, true);
            }
            else
            {
                this.SaveBlankImage();

                using (WebClientWithShortTimeout webClient = new WebClientWithShortTimeout())
                {
                    try
                    {
                        webClient.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko";
                        var downloadedJson = webClient.DownloadString(string.Format(CultureInfo.InvariantCulture, "https://embed.spotify.com/oembed/?url=spotify:album:{0}", albumId));

                        if (!string.IsNullOrEmpty(downloadedJson))
                        {
                            dynamic jsonSummary = SimpleJson.DeserializeObject(downloadedJson);

                            string imageUrl = jsonSummary.thumbnail_url.ToString().Replace("cover", string.Format(CultureInfo.InvariantCulture, "{0}", (int)Globals.ArtworkResolution));

                            if (Globals.KeepSpotifyAlbumArtwork)
                            {
                                webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadSpotifyFileCompleted);
                                webClient.DownloadFileAsync(new Uri(imageUrl), artworkImagePath, artworkImagePath);
                            }
                            else
                            {
                                webClient.DownloadFileAsync(new Uri(imageUrl), this.DefaultArtworkFilePath);
                            }
                        }
                    }
                    catch (WebException)
                    {
                        this.SaveBlankImage();
                    }
                }
            }
        }
Example #8
0
        private void DownloadSpotifyAlbumArtwork(dynamic jsonSummary)
        {
            string albumId = jsonSummary.id.ToString();

            string artworkDirectory = @Application.StartupPath + @"\SpotifyArtwork";
            string artworkImagePath = string.Format(CultureInfo.InvariantCulture, @"{0}\{1}.jpg", artworkDirectory, albumId);

            if (!Directory.Exists(artworkDirectory))
            {
                Directory.CreateDirectory(artworkDirectory);
            }

            FileInfo fileInfo = new FileInfo(artworkImagePath);

            if (fileInfo.Exists && fileInfo.Length > 0)
            {
                fileInfo.CopyTo(this.DefaultArtworkFilePath, true);
            }
            else
            {
                this.SaveBlankImage();

                using (WebClientWithShortTimeout webClient = new WebClientWithShortTimeout())
                {
                    try
                    {
                        // This assumes that the Spotify image array will always have three results (which in all of my tests it has so far)
                        string imageUrl = string.Empty;

                        switch (Globals.ArtworkResolution)
                        {
                            case Globals.AlbumArtworkResolution.Large:
                                imageUrl = jsonSummary.images[0].url.ToString();
                                break;

                            case Globals.AlbumArtworkResolution.Medium:
                                imageUrl = jsonSummary.images[1].url.ToString();
                                break;

                            case Globals.AlbumArtworkResolution.Tiny:
                                imageUrl = jsonSummary.images[2].url.ToString();
                                break;

                            default:
                                imageUrl = jsonSummary.images[0].url.ToString();
                                break;
                        }

                        webClient.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko";

                        if (Globals.KeepSpotifyAlbumArtwork)
                        {
                            webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadSpotifyFileCompleted);
                            webClient.DownloadFileAsync(new Uri(imageUrl), artworkImagePath, artworkImagePath);
                        }
                        else
                        {
                            webClient.DownloadFileAsync(new Uri(imageUrl), this.DefaultArtworkFilePath);
                        }

                        this.SavedBlankImage = false;
                    }
                    catch (WebException)
                    {
                        this.SaveBlankImage();
                    }
                }
            }
        }