public IEnumerable <Track> AddArtistSongsToPlaylist(Artist artist) { const int numSongsPerArtist = 3; //TODO: Expose this to the user. TrackList popularSongs = _client.GetArtistTopTracks(artist); List <Track> songsToAdd = new List <Track>(numSongsPerArtist); foreach (Track popularTrack in popularSongs.Tracks) { if (!this.ContainsTrack(popularTrack)) { songsToAdd.Add(popularTrack); if (songsToAdd.Count >= numSongsPerArtist) { break; } } } if (!songsToAdd.Any()) { AlbumInfoList albumList = _client.GetArtistAlbums(artist); foreach (AlbumInfo album in albumList.Items) { AlbumTrackList albumTrackList = _client.GetAlbumTracks(album); IEnumerable <Track> albumTracksByPopularity = albumTrackList.Tracks.OrderByDescending(track => track.Popularity); foreach (Track albumTrack in albumTracksByPopularity) { if (!this.ContainsTrack(albumTrack)) { songsToAdd.Add(albumTrack); if (songsToAdd.Count >= numSongsPerArtist) { break; } } } if (songsToAdd.Count >= numSongsPerArtist) { break; } } } _client.AddTracksToPlaylist(_playlist, songsToAdd); return(songsToAdd); }