Skip to content

Commit 17639a9

Browse files
wgraham17JohnnyCrazy
authored andcommitted
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
1 parent de30c50 commit 17639a9

File tree

10 files changed

+295
-0
lines changed

10 files changed

+295
-0
lines changed

SpotifyAPI.Docs/docs/SpotifyWebAPI/tracks.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,22 @@ Console.WriteLine(track.Name);
3838
```
3939

4040
---
41+
##GetAudioAnalysis
42+
43+
> Get a detailed audio analysis for a single track identified by its unique Spotify ID.
44+
45+
**Paramters**
46+
47+
|Name|Description|Example|
48+
|--------------|-------------------------|-------------------------|
49+
|id| The Spotify ID for the track. | `"6Y1CLPwYe7zvI8PJiWVz6T"`
50+
51+
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.
52+
53+
**Usage**
54+
```cs
55+
AudioAnalysis analysis = _spotify.GetAudioAnalysis("6Y1CLPwYe7zvI8PJiWVz6T");
56+
Console.WriteLine(analysis.Meta.DetailedStatus);
57+
```
58+
59+
---

SpotifyAPI/SpotifyAPI.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@
8080
<Compile Include="Web\Auth\ClientCredentialsAuth.cs" />
8181
<Compile Include="Web\Enums\FollowType.cs" />
8282
<Compile Include="Web\Auth\ImplicitGrantAuth.cs" />
83+
<Compile Include="Web\Models\AnalysisSegment.cs" />
84+
<Compile Include="Web\Models\AnalysisTimeSlice.cs" />
85+
<Compile Include="Web\Models\AnalysisMeta.cs" />
86+
<Compile Include="Web\Models\AnalysisSection.cs" />
87+
<Compile Include="Web\Models\AnalysisTrack.cs" />
8388
<Compile Include="Web\Models\ArrayResponse.cs" />
89+
<Compile Include="Web\Models\AudioAnalysis.cs" />
8490
<Compile Include="Web\Models\AudioFeatures.cs" />
8591
<Compile Include="Web\Models\AvailabeDevices.cs" />
8692
<Compile Include="Web\Models\BasicModel.cs" />

SpotifyAPI/Web/Models/AnalysisMeta.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Newtonsoft.Json;
2+
3+
namespace SpotifyAPI.Web.Models
4+
{
5+
public class AnalysisMeta
6+
{
7+
[JsonProperty("analyzer_platform")]
8+
public string AnalyzerVersion { get; set; }
9+
10+
[JsonProperty("platform")]
11+
public string Platform { get; set; }
12+
13+
[JsonProperty("status_code")]
14+
public int StatusCode { get; set; }
15+
16+
[JsonProperty("detailed_status")]
17+
public string DetailedStatus { get; set; }
18+
19+
[JsonProperty("timestamp")]
20+
public long Timestamp { get; set; }
21+
22+
[JsonProperty("analysis_time")]
23+
public double AnalysisTime { get; set; }
24+
25+
[JsonProperty("input_process")]
26+
public string InputProcess { get; set; }
27+
}
28+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Newtonsoft.Json;
2+
3+
namespace SpotifyAPI.Web.Models
4+
{
5+
public class AnalysisSection
6+
{
7+
[JsonProperty("start")]
8+
public double Start { get; set; }
9+
10+
[JsonProperty("duration")]
11+
public double Duration { get; set; }
12+
13+
[JsonProperty("confidence")]
14+
public double Confidence { get; set; }
15+
16+
[JsonProperty("loudness")]
17+
public double Loudness { get; set; }
18+
19+
[JsonProperty("tempo")]
20+
public double Tempo { get; set; }
21+
22+
[JsonProperty("tempo_confidence")]
23+
public double TempoConfidence { get; set; }
24+
25+
[JsonProperty("key")]
26+
public int Key { get; set; }
27+
28+
[JsonProperty("key_confidence")]
29+
public double KeyConfidence { get; set; }
30+
31+
[JsonProperty("mode")]
32+
public int Mode { get; set; }
33+
34+
[JsonProperty("mode_confidence")]
35+
public double ModeConfidence { get; set; }
36+
37+
[JsonProperty("time_signature")]
38+
public int TimeSignature { get; set; }
39+
40+
[JsonProperty("time_signature_confidence")]
41+
public double TimeSignatureConfidence { get; set; }
42+
}
43+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Newtonsoft.Json;
2+
using System.Collections.Generic;
3+
4+
namespace SpotifyAPI.Web.Models
5+
{
6+
public class AnalysisSegment
7+
{
8+
[JsonProperty("start")]
9+
public double Start { get; set; }
10+
11+
[JsonProperty("duration")]
12+
public double Duration { get; set; }
13+
14+
[JsonProperty("confidence")]
15+
public double Confidence { get; set; }
16+
17+
[JsonProperty("loudness_start")]
18+
public double LoudnessStart { get; set; }
19+
20+
[JsonProperty("loudness_max_time")]
21+
public double LoudnessMaxTime { get; set; }
22+
23+
[JsonProperty("loudness_max")]
24+
public double LoudnessMax { get; set; }
25+
26+
[JsonProperty("loudness_end")]
27+
public double LoudnessEnd { get; set; }
28+
29+
[JsonProperty("pitches")]
30+
public List<double> Pitches { get; set; }
31+
32+
[JsonProperty("timbre")]
33+
public List<double> Timbre { get; set; }
34+
}
35+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Newtonsoft.Json;
2+
3+
namespace SpotifyAPI.Web.Models
4+
{
5+
public class AnalysisTimeSlice
6+
{
7+
[JsonProperty("start")]
8+
public double Start { get; set; }
9+
10+
[JsonProperty("duration")]
11+
public double Duration { get; set; }
12+
13+
[JsonProperty("confidence")]
14+
public double Confidence { get; set; }
15+
}
16+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using Newtonsoft.Json;
2+
3+
namespace SpotifyAPI.Web.Models
4+
{
5+
public class AnalysisTrack
6+
{
7+
[JsonProperty("num_samples")]
8+
public int NumSamples { get; set; }
9+
10+
[JsonProperty("duration")]
11+
public double Duration { get; set; }
12+
13+
[JsonProperty("sample_md5")]
14+
public string SampleMD5 { get; set; }
15+
16+
[JsonProperty("offset_seconds")]
17+
public double OffsetSeconds { get; set; }
18+
19+
[JsonProperty("window_seconds")]
20+
public double WindowSeconds { get; set; }
21+
22+
[JsonProperty("analysis_sample_rate")]
23+
public int AnalysisSampleRate { get; set; }
24+
25+
[JsonProperty("analysis_channels")]
26+
public int AnalysisChannels { get; set; }
27+
28+
[JsonProperty("end_of_fade_in")]
29+
public double EndOfFadeIn { get; set; }
30+
31+
[JsonProperty("start_of_fade_out")]
32+
public double StartOfFadeOut { get; set; }
33+
34+
[JsonProperty("loudness")]
35+
public double Loudness { get; set; }
36+
37+
[JsonProperty("tempo")]
38+
public double Tempo { get; set; }
39+
40+
[JsonProperty("tempo_confidence")]
41+
public double TempoConfidence { get; set; }
42+
43+
[JsonProperty("time_signature")]
44+
public double TimeSignature { get; set; }
45+
46+
[JsonProperty("time_signature_confidence")]
47+
public double TimeSignatureConfidence { get; set; }
48+
49+
[JsonProperty("key")]
50+
public int Key { get; set; }
51+
52+
[JsonProperty("key_confidence")]
53+
public double KeyConfidence { get; set; }
54+
55+
[JsonProperty("mode")]
56+
public int Mode { get; set; }
57+
58+
[JsonProperty("mode_confidence")]
59+
public double ModeConfidence { get; set; }
60+
61+
[JsonProperty("codestring")]
62+
public string Codestring { get; set; }
63+
64+
[JsonProperty("code_version")]
65+
public double CodeVersion { get; set; }
66+
67+
[JsonProperty("echoprintstring")]
68+
public string Echoprintstring { get; set; }
69+
70+
[JsonProperty("echoprint_version")]
71+
public double EchoprintVersion { get; set; }
72+
73+
[JsonProperty("synchstring")]
74+
public string Synchstring { get; set; }
75+
76+
[JsonProperty("synch_version")]
77+
public double SynchVersion { get; set; }
78+
79+
[JsonProperty("rhythmstring")]
80+
public string Rhythmstring { get; set; }
81+
82+
[JsonProperty("rhythm_version")]
83+
public double RhythmVersion { get; set; }
84+
85+
}
86+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Newtonsoft.Json;
2+
using System.Collections.Generic;
3+
4+
namespace SpotifyAPI.Web.Models
5+
{
6+
public class AudioAnalysis : BasicModel
7+
{
8+
[JsonProperty("bars")]
9+
public List<AnalysisTimeSlice> Bars { get; set; }
10+
11+
[JsonProperty("beats")]
12+
public List<AnalysisTimeSlice> Beats { get; set; }
13+
14+
[JsonProperty("meta")]
15+
public AnalysisMeta Meta { get; set; }
16+
17+
[JsonProperty("sections")]
18+
public List<AnalysisSection> Sections { get; set; }
19+
20+
[JsonProperty("segments")]
21+
public List<AnalysisSegment> Segments { get; set; }
22+
23+
[JsonProperty("tatums")]
24+
public List<AnalysisTimeSlice> Tatums { get; set; }
25+
26+
[JsonProperty("track")]
27+
public AnalysisTrack Track { get; set; }
28+
}
29+
}

SpotifyAPI/Web/SpotifyWebAPI.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,28 @@ public Task<FullTrack> GetTrackAsync(string id, string market = "")
17801780
return DownloadDataAsync<FullTrack>(_builder.GetTrack(id, market));
17811781
}
17821782

1783+
/// <summary>
1784+
/// Get a detailed audio analysis for a single track identified by its unique Spotify ID.
1785+
/// </summary>
1786+
/// <param name="id">The Spotify ID for the track.</param>
1787+
/// <returns></returns>
1788+
/// <remarks>AUTH NEEDED</remarks>
1789+
public AudioAnalysis GetAudioAnalysis(string id)
1790+
{
1791+
return DownloadData<AudioAnalysis>(_builder.GetAudioAnalysis(id));
1792+
}
1793+
1794+
/// <summary>
1795+
/// Get a detailed audio analysis for a single track identified by its unique Spotify ID asynchronously.
1796+
/// </summary>
1797+
/// <param name="id">The Spotify ID for the track.</param>
1798+
/// <returns></returns>
1799+
/// <remarks>AUTH NEEDED</remarks>
1800+
public Task<AudioAnalysis> GetAudioAnalysisAsync(string id)
1801+
{
1802+
return DownloadDataAsync<AudioAnalysis>(_builder.GetAudioAnalysis(id));
1803+
}
1804+
17831805
/// <summary>
17841806
/// Get audio feature information for a single track identified by its unique Spotify ID.
17851807
/// </summary>

SpotifyAPI/Web/SpotifyWebBuilder.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,17 @@ public string GetTrack(string id, string market = "")
817817
return $"{APIBase}/tracks/{id}?market={market}";
818818
}
819819

820+
/// <summary>
821+
/// Get a detailed audio analysis for a single track identified by its unique Spotify ID.
822+
/// </summary>
823+
/// <param name="id">The Spotify ID for the track.</param>
824+
/// <returns></returns>
825+
/// <remarks>AUTH NEEDED</remarks>
826+
public string GetAudioAnalysis(string id)
827+
{
828+
return $"{APIBase}/audio-analysis/{id}";
829+
}
830+
820831
/// <summary>
821832
/// Get audio feature information for a single track identified by its unique Spotify ID.
822833
/// </summary>

0 commit comments

Comments
 (0)