public static SpotifyAlbum DownloadAlbumInfo(string albumId)
        {
            var uri          = GetAlbumUri(albumId);
            var spotifyAlbum = new SpotifyAlbum();

            HttpHelper.DownloadString(uri, (response) =>
            {
                dynamic album = JsonConvert.DeserializeObject(response);

                spotifyAlbum.Name = album["name"].ToString();

                var songCount = album["total_tracks"].ToString();
                spotifyAlbum.SongCollection = new SpotifySong[int.Parse(songCount)];

                for (var i = 0; i < spotifyAlbum.SongCollection.Length; i++)
                {
                    var songData = album["tracks"]["items"][i].href.ToString();
                    songData     = Path.GetFileName(songData);

                    spotifyAlbum.SongCollection[i] = SpotifySong.DownloadSongInfo(songData);
                }
                spotifyAlbum.Artwork = spotifyAlbum.SongCollection[0].Artwork;
            });

            return(spotifyAlbum);
        }
Example #2
0
        public static SpotifySong DownloadSongInfo(string songId)
        {
            var builder     = GetSongUri(songId);
            var spotifySong = new SpotifySong();

            HttpHelper.DownloadString(builder, (response) =>
            {
                dynamic song = JsonConvert.DeserializeObject(response);

                spotifySong.Track  = song["name"].ToString();
                spotifySong.Album  = song["album"].name;
                spotifySong.Artist = song["artists"][0].name;
                spotifySong.Number = int.Parse((string)song["track_number"].ToString());

                var duration         = int.Parse(song["duration_ms"].ToString());
                spotifySong.Duration = TimeSpan.FromMilliseconds(duration);

                if (song["album"]["images"] != null)
                {
                    var imagePaths = song["album"]["images"];
                    if (imagePaths.Next != null)
                    {
                        var albumLocation           = (string)imagePaths[0]["url"].ToString();
                        spotifySong.artworkLocation = albumLocation;
                    }
                }

                var dateTime = DateTime.MinValue;
                var values   = song["album"]["release_date"].ToString().Split(new char[] { '-' });
                switch (values.Length)
                {
                case 0:
                    dateTime = DateTime.MinValue;
                    break;

                case 1:
                    dateTime = new DateTime(int.Parse(values[0]), 1, 1);
                    break;

                case 2:
                    dateTime = new DateTime(int.Parse(values[0]), int.Parse(values[1]), 1);
                    break;

                case 3:
                    dateTime = new DateTime(int.Parse(values[0]), int.Parse(values[1]), int.Parse(values[2]));
                    break;
                }
            });

            return(spotifySong);
        }
        private static IEnumerable <SpotifySong> GetSet(dynamic setData)
        {
            var songCollection = new List <SpotifySong>();
            var items          = setData["items"];
            var index          = 0;

            for (index = 0; index < items.Count; index++)
            {
                var         songUri = items[index]["track"].href.ToString();
                SpotifySong song    = SpotifySong.DownloadSongInfo(Path.GetFileName(songUri));
                songCollection.Add(song);
            }

            return(songCollection);
        }