Add Audio Track Analysis models and API endpoint (#161)

* Add Audio Track Analysis models and API endpoint

* Update docs

* Add link to EchoNest archived docs for AudioAnalysis model
This commit is contained in:
Will Graham 2017-07-02 13:37:11 -04:00 committed by Jonas Dellinger
parent de30c50f0b
commit 17639a9b54
10 changed files with 295 additions and 0 deletions

View File

@ -38,3 +38,22 @@ Console.WriteLine(track.Name);
``` ```
--- ---
##GetAudioAnalysis
> Get a detailed audio analysis for a single track identified by its unique Spotify ID.
**Paramters**
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|id| The Spotify ID for the track. | `"6Y1CLPwYe7zvI8PJiWVz6T"`
Returns a AudioAnalysis. This object is currently lacking Spotify documentation but archived [EchoNest documentation](https://web.archive.org/web/20160528174915/http://developer.echonest.com/docs/v4/_static/AnalyzeDocumentation.pdf) is relevant.
**Usage**
```cs
AudioAnalysis analysis = _spotify.GetAudioAnalysis("6Y1CLPwYe7zvI8PJiWVz6T");
Console.WriteLine(analysis.Meta.DetailedStatus);
```
---

View File

@ -80,7 +80,13 @@
<Compile Include="Web\Auth\ClientCredentialsAuth.cs" /> <Compile Include="Web\Auth\ClientCredentialsAuth.cs" />
<Compile Include="Web\Enums\FollowType.cs" /> <Compile Include="Web\Enums\FollowType.cs" />
<Compile Include="Web\Auth\ImplicitGrantAuth.cs" /> <Compile Include="Web\Auth\ImplicitGrantAuth.cs" />
<Compile Include="Web\Models\AnalysisSegment.cs" />
<Compile Include="Web\Models\AnalysisTimeSlice.cs" />
<Compile Include="Web\Models\AnalysisMeta.cs" />
<Compile Include="Web\Models\AnalysisSection.cs" />
<Compile Include="Web\Models\AnalysisTrack.cs" />
<Compile Include="Web\Models\ArrayResponse.cs" /> <Compile Include="Web\Models\ArrayResponse.cs" />
<Compile Include="Web\Models\AudioAnalysis.cs" />
<Compile Include="Web\Models\AudioFeatures.cs" /> <Compile Include="Web\Models\AudioFeatures.cs" />
<Compile Include="Web\Models\AvailabeDevices.cs" /> <Compile Include="Web\Models\AvailabeDevices.cs" />
<Compile Include="Web\Models\BasicModel.cs" /> <Compile Include="Web\Models\BasicModel.cs" />

View File

@ -0,0 +1,28 @@
using Newtonsoft.Json;
namespace SpotifyAPI.Web.Models
{
public class AnalysisMeta
{
[JsonProperty("analyzer_platform")]
public string AnalyzerVersion { get; set; }
[JsonProperty("platform")]
public string Platform { get; set; }
[JsonProperty("status_code")]
public int StatusCode { get; set; }
[JsonProperty("detailed_status")]
public string DetailedStatus { get; set; }
[JsonProperty("timestamp")]
public long Timestamp { get; set; }
[JsonProperty("analysis_time")]
public double AnalysisTime { get; set; }
[JsonProperty("input_process")]
public string InputProcess { get; set; }
}
}

View File

@ -0,0 +1,43 @@
using Newtonsoft.Json;
namespace SpotifyAPI.Web.Models
{
public class AnalysisSection
{
[JsonProperty("start")]
public double Start { get; set; }
[JsonProperty("duration")]
public double Duration { get; set; }
[JsonProperty("confidence")]
public double Confidence { get; set; }
[JsonProperty("loudness")]
public double Loudness { get; set; }
[JsonProperty("tempo")]
public double Tempo { get; set; }
[JsonProperty("tempo_confidence")]
public double TempoConfidence { get; set; }
[JsonProperty("key")]
public int Key { get; set; }
[JsonProperty("key_confidence")]
public double KeyConfidence { get; set; }
[JsonProperty("mode")]
public int Mode { get; set; }
[JsonProperty("mode_confidence")]
public double ModeConfidence { get; set; }
[JsonProperty("time_signature")]
public int TimeSignature { get; set; }
[JsonProperty("time_signature_confidence")]
public double TimeSignatureConfidence { get; set; }
}
}

View File

@ -0,0 +1,35 @@
using Newtonsoft.Json;
using System.Collections.Generic;
namespace SpotifyAPI.Web.Models
{
public class AnalysisSegment
{
[JsonProperty("start")]
public double Start { get; set; }
[JsonProperty("duration")]
public double Duration { get; set; }
[JsonProperty("confidence")]
public double Confidence { get; set; }
[JsonProperty("loudness_start")]
public double LoudnessStart { get; set; }
[JsonProperty("loudness_max_time")]
public double LoudnessMaxTime { get; set; }
[JsonProperty("loudness_max")]
public double LoudnessMax { get; set; }
[JsonProperty("loudness_end")]
public double LoudnessEnd { get; set; }
[JsonProperty("pitches")]
public List<double> Pitches { get; set; }
[JsonProperty("timbre")]
public List<double> Timbre { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using Newtonsoft.Json;
namespace SpotifyAPI.Web.Models
{
public class AnalysisTimeSlice
{
[JsonProperty("start")]
public double Start { get; set; }
[JsonProperty("duration")]
public double Duration { get; set; }
[JsonProperty("confidence")]
public double Confidence { get; set; }
}
}

View File

@ -0,0 +1,86 @@
using Newtonsoft.Json;
namespace SpotifyAPI.Web.Models
{
public class AnalysisTrack
{
[JsonProperty("num_samples")]
public int NumSamples { get; set; }
[JsonProperty("duration")]
public double Duration { get; set; }
[JsonProperty("sample_md5")]
public string SampleMD5 { get; set; }
[JsonProperty("offset_seconds")]
public double OffsetSeconds { get; set; }
[JsonProperty("window_seconds")]
public double WindowSeconds { get; set; }
[JsonProperty("analysis_sample_rate")]
public int AnalysisSampleRate { get; set; }
[JsonProperty("analysis_channels")]
public int AnalysisChannels { get; set; }
[JsonProperty("end_of_fade_in")]
public double EndOfFadeIn { get; set; }
[JsonProperty("start_of_fade_out")]
public double StartOfFadeOut { get; set; }
[JsonProperty("loudness")]
public double Loudness { get; set; }
[JsonProperty("tempo")]
public double Tempo { get; set; }
[JsonProperty("tempo_confidence")]
public double TempoConfidence { get; set; }
[JsonProperty("time_signature")]
public double TimeSignature { get; set; }
[JsonProperty("time_signature_confidence")]
public double TimeSignatureConfidence { get; set; }
[JsonProperty("key")]
public int Key { get; set; }
[JsonProperty("key_confidence")]
public double KeyConfidence { get; set; }
[JsonProperty("mode")]
public int Mode { get; set; }
[JsonProperty("mode_confidence")]
public double ModeConfidence { get; set; }
[JsonProperty("codestring")]
public string Codestring { get; set; }
[JsonProperty("code_version")]
public double CodeVersion { get; set; }
[JsonProperty("echoprintstring")]
public string Echoprintstring { get; set; }
[JsonProperty("echoprint_version")]
public double EchoprintVersion { get; set; }
[JsonProperty("synchstring")]
public string Synchstring { get; set; }
[JsonProperty("synch_version")]
public double SynchVersion { get; set; }
[JsonProperty("rhythmstring")]
public string Rhythmstring { get; set; }
[JsonProperty("rhythm_version")]
public double RhythmVersion { get; set; }
}
}

View File

@ -0,0 +1,29 @@
using Newtonsoft.Json;
using System.Collections.Generic;
namespace SpotifyAPI.Web.Models
{
public class AudioAnalysis : BasicModel
{
[JsonProperty("bars")]
public List<AnalysisTimeSlice> Bars { get; set; }
[JsonProperty("beats")]
public List<AnalysisTimeSlice> Beats { get; set; }
[JsonProperty("meta")]
public AnalysisMeta Meta { get; set; }
[JsonProperty("sections")]
public List<AnalysisSection> Sections { get; set; }
[JsonProperty("segments")]
public List<AnalysisSegment> Segments { get; set; }
[JsonProperty("tatums")]
public List<AnalysisTimeSlice> Tatums { get; set; }
[JsonProperty("track")]
public AnalysisTrack Track { get; set; }
}
}

View File

@ -1780,6 +1780,28 @@ namespace SpotifyAPI.Web
return DownloadDataAsync<FullTrack>(_builder.GetTrack(id, market)); return DownloadDataAsync<FullTrack>(_builder.GetTrack(id, market));
} }
/// <summary>
/// Get a detailed audio analysis for a single track identified by its unique Spotify ID.
/// </summary>
/// <param name="id">The Spotify ID for the track.</param>
/// <returns></returns>
/// <remarks>AUTH NEEDED</remarks>
public AudioAnalysis GetAudioAnalysis(string id)
{
return DownloadData<AudioAnalysis>(_builder.GetAudioAnalysis(id));
}
/// <summary>
/// Get a detailed audio analysis for a single track identified by its unique Spotify ID asynchronously.
/// </summary>
/// <param name="id">The Spotify ID for the track.</param>
/// <returns></returns>
/// <remarks>AUTH NEEDED</remarks>
public Task<AudioAnalysis> GetAudioAnalysisAsync(string id)
{
return DownloadDataAsync<AudioAnalysis>(_builder.GetAudioAnalysis(id));
}
/// <summary> /// <summary>
/// Get audio feature information for a single track identified by its unique Spotify ID. /// Get audio feature information for a single track identified by its unique Spotify ID.
/// </summary> /// </summary>

View File

@ -817,6 +817,17 @@ namespace SpotifyAPI.Web
return $"{APIBase}/tracks/{id}?market={market}"; return $"{APIBase}/tracks/{id}?market={market}";
} }
/// <summary>
/// Get a detailed audio analysis for a single track identified by its unique Spotify ID.
/// </summary>
/// <param name="id">The Spotify ID for the track.</param>
/// <returns></returns>
/// <remarks>AUTH NEEDED</remarks>
public string GetAudioAnalysis(string id)
{
return $"{APIBase}/audio-analysis/{id}";
}
/// <summary> /// <summary>
/// Get audio feature information for a single track identified by its unique Spotify ID. /// Get audio feature information for a single track identified by its unique Spotify ID.
/// </summary> /// </summary>