TRock.Music.Spotify.SpotifySongProvider.GetSongs C# (CSharp) Method

GetSongs() public method

public GetSongs ( string query, CancellationToken cancellationToken ) : Task>
query string
cancellationToken System.Threading.CancellationToken
return Task>
        public Task<IEnumerable<Song>> GetSongs(string query, CancellationToken cancellationToken)
        {
            return _client
                .GetAsync(new Uri("http://ws.spotify.com/search/1/track.json?q=" + query), cancellationToken)
                .ContinueWith(requestTask =>
                {
                    var songs = new List<Song>();
                    var response = requestTask.Result;
                    response.EnsureSuccessStatusCode();

                    var content = response.Content.ReadAsStringAsync().Result;
                    var result = JsonConvert.DeserializeObject<dynamic>(content);

                    var tracks = (IEnumerable<dynamic>)(result["tracks"].HasValues ? result["tracks"] : new dynamic[0]);

                    foreach (dynamic song in tracks)
                    {
                        songs.Add(new Song
                        {
                            Id = song["href"],
                            Name = song["name"],
                            Provider = ProviderName,
                            TotalSeconds = (int)song["length"],
                            Album = new Album
                            {
                                Id = song["album"] != null ? song["album"]["href"] : null,
                                Provider = ProviderName,
                                Name = song["album"] != null ? song["album"]["name"] : null,
                                CoverArt = _imageProvider.GetCoverArtUri(Convert.ToString(song["album"] != null ? song["album"]["href"] : null)) ?? string.Empty
                            },
                            Artist = new Artist
                            {
                                Id = song["artists"].HasValues ? song["artists"][0]["href"] : null,
                                Name = song["artists"].HasValues ? song["artists"][0]["name"] : null
                            }
                        });
                    }

                    return (IEnumerable<Song>)songs;
                });
        }