private void UpdateTrackFeatures(TrackAudioFeatures features) { DataModel.Track.Features.Acousticness = features.Acousticness * 100; DataModel.Track.Features.Danceability = features.Danceability * 100; DataModel.Track.Features.Energy = features.Energy * 100; DataModel.Track.Features.Instrumentalness = features.Instrumentalness * 100; DataModel.Track.Features.Liveness = features.Liveness * 100; DataModel.Track.Features.Loudness = features.Loudness; DataModel.Track.Features.Speechiness = features.Speechiness * 100; DataModel.Track.Features.Valence = features.Valence * 100; DataModel.Track.Features.Tempo = features.Tempo; DataModel.Track.Features.Key = (Key)features.Key; DataModel.Track.Features.Mode = (Mode)features.Mode; DataModel.Track.Features.TimeSignature = features.TimeSignature; }
public async Task <Features> GetFeatures(Spotify sp, SpotterAzure_dbContext dbContext) { if (DateTime.Now.AddDays(-7) > this.TrueAt.Value || this.Features == null) { try { TrackAudioFeatures features = await sp.spotify.Tracks.GetAudioFeatures(TrackId); this.Features = JObject.FromObject(features).ToString(); } catch { return(null); } finally { dbContext.Tracks.Update(this); } } return(JObject.Parse(this.Features).ToObject <Features>()); }
private async Task UpdateTrackInfo(FullTrack track) { string trackId = track.Uri.Split(':').Last(); if (trackId != _trackId) { UpdateBasicTrackInfo(track); try { TrackAudioFeatures features = await _spotify.Tracks.GetAudioFeatures(trackId); UpdateTrackFeatures(features); } catch (Exception e) { _logger.Error("Error updating track audio features", e); } try { _analysis = await _spotify.Tracks.GetAudioAnalysis(trackId); } catch (Exception e) { _logger.Error("Error getting track audio analysis", e); } Image image = track.Album.Images.Last(); if (image.Url != _albumArtUrl) { await UpdateAlbumArtColors(image.Url); _albumArtUrl = image.Url; } _trackId = trackId; } }
private async Task UpdateTrackInfo(FullTrack track) { string trackId = track.Uri.Split(':').Last(); if (trackId != _trackId) { UpdateBasicTrackInfo(track); TrackAudioFeatures features = await _spotify.Tracks.GetAudioFeatures(trackId); UpdateTrackFeatures(features); Image image = track.Album.Images.Last(); if (image.Url != _albumArtUrl) { await UpdateAlbumArtColors(image.Url); _albumArtUrl = image.Url; } _trackId = trackId; } }