public static IList<SongDto> CreatePlaylistResponse(JObject response) { var result = ((response[EchonestResources.Response] as JObject)[EchonestResources.Songs] as JArray); var songs = new List<SongDto>(); if (result == null) return songs; foreach (var songResult in result) { var newSong = new SongDto(); var song = songResult as JObject; newSong.Name = song[EchonestResources.Title]?.ToString(); newSong.ArtistName = song[EchonestResources.ArtistName]?.ToString(); newSong.EchonestId = song[EchonestResources.Id]?.ToString(); newSong.ArtistEchonestId = song[EchonestResources.ArtistId]?.ToString(); var trackDetails = (song[EchonestResources.Tracks] as JArray)?.First as JObject; newSong.SpotifyId = trackDetails[EchonestResources.ForeignId]?.ToString(); songs.Add(newSong); } return songs; }
public static void UpdateSongData(SparqlResultSet resultSet, SongDto songDto) { var result = resultSet.Results.FirstOrDefault(); if (result == null) return; songDto.Id = result.Value(SparqlResources.Song).ToString(); if (result.HasValue(SparqlResources.Thumbnail)) { songDto.Thumbnail = result.Value(SparqlResources.Thumbnail)?.ToString(); } }
public void GetSongByNameAndArtist(SongDto songDto) { var query = string.Format(SparqlResources.GetSongByNameAndArtistName, songDto.Name.ToLower(), songDto.ArtistName.ToLower()); var resultSet = sparqlRemoteEndpoint.QueryWithResultSet(query); DbpediaHelper.UpdateSongData(resultSet, songDto); }
public IHttpActionResult AssociateWithDbpedia(SongDto song) { dbpediaEndpoint.GetSongByNameAndArtist(song); return Ok(song); }