Skip to content

Commit

Permalink
Add Audio Track Analysis models and API endpoint (#161)
Browse files Browse the repository at this point in the history
* Add Audio Track Analysis models and API endpoint

* Update docs

* Add link to EchoNest archived docs for AudioAnalysis model
  • Loading branch information
wgraham17 authored and JohnnyCrazy committed Jul 2, 2017
1 parent de30c50 commit 17639a9
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 0 deletions.
19 changes: 19 additions & 0 deletions SpotifyAPI.Docs/docs/SpotifyWebAPI/tracks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```

---
6 changes: 6 additions & 0 deletions SpotifyAPI/SpotifyAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@
<Compile Include="Web\Auth\ClientCredentialsAuth.cs" />
<Compile Include="Web\Enums\FollowType.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\AudioAnalysis.cs" />
<Compile Include="Web\Models\AudioFeatures.cs" />
<Compile Include="Web\Models\AvailabeDevices.cs" />
<Compile Include="Web\Models\BasicModel.cs" />
Expand Down
28 changes: 28 additions & 0 deletions SpotifyAPI/Web/Models/AnalysisMeta.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
43 changes: 43 additions & 0 deletions SpotifyAPI/Web/Models/AnalysisSection.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
35 changes: 35 additions & 0 deletions SpotifyAPI/Web/Models/AnalysisSegment.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
16 changes: 16 additions & 0 deletions SpotifyAPI/Web/Models/AnalysisTimeSlice.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
86 changes: 86 additions & 0 deletions SpotifyAPI/Web/Models/AnalysisTrack.cs
Original file line number Diff line number Diff line change
@@ -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; }

}
}
29 changes: 29 additions & 0 deletions SpotifyAPI/Web/Models/AudioAnalysis.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
22 changes: 22 additions & 0 deletions SpotifyAPI/Web/SpotifyWebAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,28 @@ public Task<FullTrack> GetTrackAsync(string id, string 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>
/// Get audio feature information for a single track identified by its unique Spotify ID.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions SpotifyAPI/Web/SpotifyWebBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,17 @@ public string GetTrack(string id, string 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>
/// Get audio feature information for a single track identified by its unique Spotify ID.
/// </summary>
Expand Down

0 comments on commit 17639a9

Please sign in to comment.