public IList <Track> GetRecommendations(List <Artist> artists, List <Track> tracks) { //Fix for Double.ToString() using , System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; Dictionary <string, string> seedDictionary = new Dictionary <string, string>(); TrackFeatures recommendationFeatures = new TrackFeatures(); if (tracks.Count > 0) { recommendationFeatures = AnalyzeTracks(tracks); seedDictionary.Add("seed_tracks", string.Join(",", tracks.ConvertAll(t => t.Id))); } else if (artists.Count > 0) { var artistsTopTracks = new List <SpotifyTrack>(); foreach (var artist in artists) { var response = Spotify.GetArtistTopTracks(artist.Id); if (response.IsSuccess) { artistsTopTracks.AddRange(response.Content.Tracks); } } recommendationFeatures = AnalyzeTracks(artistsTopTracks.ConvertAll(SpotifyFactory.CreateTrack)); seedDictionary.Add("seed_artists", string.Join(",", artists.ConvertAll(t => t.Id))); } foreach (var feature in recommendationFeatures.GetType().GetProperties()) { seedDictionary.Add($"target_{feature.Name.ToLower()}", feature.GetValue(recommendationFeatures).ToString()); } var recommendationResponse = Spotify.GetSeedRecommendations(seedDictionary); if (recommendationResponse.IsSuccess) { var responseContent = recommendationResponse.Content; var returnObject = new List <Track>(); foreach (var spotifyTrack in responseContent.Tracks) { returnObject.Add(SpotifyFactory.CreateTrack(spotifyTrack)); } return(returnObject); } return(null); }
public IList <Track> GetArtistTopTracks(string artistId) { var request = Spotify.GetArtistTopTracks(artistId); if (request.IsSuccess) { var artistTopTracks = request.Content; IList <Track> returnList = new List <Track>(); foreach (var spotifyTrack in artistTopTracks.Tracks) { returnList.Add(SpotifyFactory.CreateTrack(spotifyTrack)); } return(returnList); } return(null); }