public static TheEchoNest FindBySongName(this ObjectSet <TheEchoNest> itemSet, String name) { if (string.IsNullOrEmpty(name.Trim())) { throw new ArgumentException("Searching parameters cannot be null.", "name"); } var match = (from item in itemSet where item.Song.Name == name.ToLower() select item) .FirstOrDefault(); if (match != null) { return(match); } TheEchoNest newEntry = new TheEchoNest() { ID = itemSet.GetNextID() }; itemSet.AddObject(newEntry); return(newEntry); }
public void FindBySong(Song song, SongBucket bucket) { var result = echo.Query <Search>().Execute(new SearchArgument { Title = song.Name, Artist = song.Artist.Name, Bucket = bucket }); if (result.Status.Code != ResponseCode.Success) { return; } TheEchoNest echosong = database.TheEchoNest.FindBySongName(song.Name); if (echosong == null) { return; } var track = result.Songs.FirstOrDefault(); this.UpdateAudioProperties(echosong, track); echosong.Song = song; SaveIntoDatabase(); }
private void UpdateAudioProperties(TheEchoNest song, SongBucketItem properties) { if (properties != null) { song.Tempo = properties.AudioSummary.Tempo; song.Loudness = properties.AudioSummary.Loudness; song.Key = properties.AudioSummary.Key; song.Mode = properties.AudioSummary.Mode; song.Energy = properties.AudioSummary.Energy; song.Danceability = properties.AudioSummary.Danceability; } }
private void InsertSongs(PlaylistResponse result, string genre) { for (int i = 0; i < result.Songs.Count; i++) { var track = result.Songs[i]; Song song = database.Song.FindByName(track.Title); this.UpdateSong(song, track.ArtistName, genre); TheEchoNest echosong = database.TheEchoNest.FindBySongName(song.Name); if (echosong == null) { continue; } this.UpdateAudioProperties(echosong, track); echosong.Song = song; SaveIntoDatabase(); } }