示例#1
0
        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);
        }
        public static SpotifyArtist DownloadArtistInfo(string artistId, bool getAllAlbums = true)
        {
            var uri           = GetArtistUri(artistId);
            var spotifyArtist = new SpotifyArtist();

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

                if (getAllAlbums)
                {
                    var albumUri = new Uri(string.Format("{0}artists/{1}/albums", HttpHelper.SpotifyApi, artistId));
                    HttpHelper.DownloadString(albumUri, (albums) =>
                    {
                        dynamic allAlbums = JsonConvert.DeserializeObject(albums);

                        int albumCount = int.Parse(allAlbums["limit"].ToString());
                        Console.WriteLine(albumCount);
                        spotifyArtist.AlbumCollection = new SpotifyAlbum[albumCount];
                        dynamic itemArray             = allAlbums["items"];

                        for (var i = 0; i < albumCount; i++)
                        {
                            var albumId        = Path.GetFileName(itemArray[i].href.ToString());
                            SpotifyAlbum album = SpotifyAlbum.DownloadAlbumInfo(albumId);
                            spotifyArtist.AlbumCollection[i] = album;

                            Console.WriteLine(album.Name);
                        }
                    });
                }

                spotifyArtist.Name = (string)artistInfo.name.ToString();
            });

            return(spotifyArtist);
        }