mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2025-01-11 06:07:45 +00:00
Added Tracks client
This commit is contained in:
parent
cd650a7e6d
commit
2f09ba25ec
2
.vscode/csharp.code-snippets
vendored
2
.vscode/csharp.code-snippets
vendored
@ -7,7 +7,7 @@
|
||||
"{",
|
||||
" public class $1",
|
||||
" {",
|
||||
" public ${2:string} ${3:Name} { get; set; }",
|
||||
" public ${2:string} ${3:Name} { get; private set; }",
|
||||
"",
|
||||
" $4",
|
||||
" }",
|
||||
|
@ -1,6 +1,20 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public interface ITracksClient
|
||||
{
|
||||
Task<TracksResponse> GetSeveral(TracksRequest request);
|
||||
|
||||
Task<TrackAudioAnalysis> GetAudioAnalysis(string trackId);
|
||||
Task<TrackAudioFeatures> GetAudioFeatures(string trackId);
|
||||
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
|
||||
Task<FullTrack> Get(string trackId);
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
|
||||
Task<FullTrack> Get(string trackId, TrackRequest request);
|
||||
|
||||
Task<TracksAudioFeaturesResponse> GetSeveralAudioFeatures(TracksAudioFeaturesRequest request);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,54 @@
|
||||
using System.Threading.Tasks;
|
||||
using SpotifyAPI.Web.Http;
|
||||
using URLs = SpotifyAPI.Web.SpotifyUrls;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class TracksClient : APIClient, ITracksClient
|
||||
{
|
||||
public TracksClient(IAPIConnector apiConnector) : base(apiConnector) { }
|
||||
|
||||
public Task<FullTrack> Get(string trackId)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(trackId, nameof(trackId));
|
||||
|
||||
return API.Get<FullTrack>(URLs.Track(trackId));
|
||||
}
|
||||
|
||||
public Task<FullTrack> Get(string trackId, TrackRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(trackId, nameof(trackId));
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
return API.Get<FullTrack>(URLs.Track(trackId), request.BuildQueryParams());
|
||||
}
|
||||
|
||||
public Task<TrackAudioAnalysis> GetAudioAnalysis(string trackId)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(trackId, nameof(trackId));
|
||||
|
||||
return API.Get<TrackAudioAnalysis>(URLs.AudioAnalysis(trackId));
|
||||
}
|
||||
|
||||
public Task<TrackAudioFeatures> GetAudioFeatures(string trackId)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(trackId, nameof(trackId));
|
||||
|
||||
return API.Get<TrackAudioFeatures>(URLs.AudioFeatures(trackId));
|
||||
}
|
||||
|
||||
public Task<TracksResponse> GetSeveral(TracksRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
return API.Get<TracksResponse>(URLs.Tracks(), request.BuildQueryParams());
|
||||
}
|
||||
|
||||
public Task<TracksAudioFeaturesResponse> GetSeveralAudioFeatures(TracksAudioFeaturesRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
return API.Get<TracksAudioFeaturesResponse>(URLs.AudioFeatures(), request.BuildQueryParams());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace SpotifyAPI.Web
|
||||
{
|
||||
public JObject BuildBodyParams()
|
||||
{
|
||||
// Make sure everything is okay before building query params
|
||||
// Make sure everything is okay before building body params
|
||||
CustomEnsure();
|
||||
|
||||
var bodyProps = GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public)
|
||||
|
8
SpotifyAPI.Web/Models/Request/TrackRequest.cs
Normal file
8
SpotifyAPI.Web/Models/Request/TrackRequest.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class TrackRequest : RequestParams
|
||||
{
|
||||
[QueryParam("market")]
|
||||
public string Market { get; set; }
|
||||
}
|
||||
}
|
17
SpotifyAPI.Web/Models/Request/TracksAudioFeaturesRequest.cs
Normal file
17
SpotifyAPI.Web/Models/Request/TracksAudioFeaturesRequest.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class TracksAudioFeaturesRequest : RequestParams
|
||||
{
|
||||
public TracksAudioFeaturesRequest(IList<string> ids)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
|
||||
|
||||
Ids = ids;
|
||||
}
|
||||
|
||||
[QueryParam("ids")]
|
||||
public IList<string> Ids { get; private set; }
|
||||
}
|
||||
}
|
20
SpotifyAPI.Web/Models/Request/TracksRequest.cs
Normal file
20
SpotifyAPI.Web/Models/Request/TracksRequest.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class TracksRequest : RequestParams
|
||||
{
|
||||
public TracksRequest(IList<string> ids)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
|
||||
|
||||
Ids = ids;
|
||||
}
|
||||
|
||||
[QueryParam("ids")]
|
||||
public IList<string> Ids { get; }
|
||||
|
||||
[QueryParam("market")]
|
||||
public string Market { get; set; }
|
||||
}
|
||||
}
|
18
SpotifyAPI.Web/Models/Response/Section.cs
Normal file
18
SpotifyAPI.Web/Models/Response/Section.cs
Normal file
@ -0,0 +1,18 @@
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class Section
|
||||
{
|
||||
public float Start { get; private set; }
|
||||
public float Duration { get; private set; }
|
||||
public float Confidence { get; private set; }
|
||||
public float Loudness { get; private set; }
|
||||
public float Tempo { get; private set; }
|
||||
public float TempoConfidence { get; private set; }
|
||||
public int Key { get; private set; }
|
||||
public float KeyConfidence { get; private set; }
|
||||
public int Mode { get; private set; }
|
||||
public float ModeConfidence { get; private set; }
|
||||
public int TimeSignature { get; private set; }
|
||||
public float TimeSignatureConfidence { get; private set; }
|
||||
}
|
||||
}
|
17
SpotifyAPI.Web/Models/Response/Segment.cs
Normal file
17
SpotifyAPI.Web/Models/Response/Segment.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class Segment
|
||||
{
|
||||
public float Start { get; private set; }
|
||||
public float Duration { get; private set; }
|
||||
public float Confidence { get; private set; }
|
||||
public float LoudnessStart { get; private set; }
|
||||
public float LoudnessMax { get; private set; }
|
||||
public float LoudnessMaxTime { get; private set; }
|
||||
public float LoudnessEnd { get; private set; }
|
||||
public List<float> Pitches { get; private set; }
|
||||
public List<float> Timbre { get; private set; }
|
||||
}
|
||||
}
|
9
SpotifyAPI.Web/Models/Response/TimeInterval.cs
Normal file
9
SpotifyAPI.Web/Models/Response/TimeInterval.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class TimeInterval
|
||||
{
|
||||
public float Start { get; private set; }
|
||||
public float Duration { get; private set; }
|
||||
public float Confidence { get; private set; }
|
||||
}
|
||||
}
|
13
SpotifyAPI.Web/Models/Response/TrackAudioAnalysis.cs
Normal file
13
SpotifyAPI.Web/Models/Response/TrackAudioAnalysis.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class TrackAudioAnalysis
|
||||
{
|
||||
public List<TimeInterval> Bars { get; private set; }
|
||||
public List<TimeInterval> Beats { get; private set; }
|
||||
public List<Section> Sections { get; private set; }
|
||||
public List<Segment> Segments { get; private set; }
|
||||
public List<TimeInterval> Tatums { get; private set; }
|
||||
}
|
||||
}
|
24
SpotifyAPI.Web/Models/Response/TrackAudioFeatures.cs
Normal file
24
SpotifyAPI.Web/Models/Response/TrackAudioFeatures.cs
Normal file
@ -0,0 +1,24 @@
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class TrackAudioFeatures
|
||||
{
|
||||
public float Acousticness { get; private set; }
|
||||
public string AnalysisUrl { get; private set; }
|
||||
public float Danceability { get; private set; }
|
||||
public int DurationMs { get; private set; }
|
||||
public float Energy { get; private set; }
|
||||
public string Id { get; private set; }
|
||||
public float Instrumentalness { get; private set; }
|
||||
public int Key { get; private set; }
|
||||
public float Liveness { get; private set; }
|
||||
public float Loudness { get; private set; }
|
||||
public int Mode { get; private set; }
|
||||
public float Speechiness { get; private set; }
|
||||
public float Tempo { get; private set; }
|
||||
public int TimeSignature { get; private set; }
|
||||
public string TrackHref { get; private set; }
|
||||
public string Type { get; private set; }
|
||||
public string Uri { get; private set; }
|
||||
public float Valence { get; private set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class TracksAudioFeaturesResponse
|
||||
{
|
||||
public List<TrackAudioFeatures> AudioFeatures { get; private set; }
|
||||
}
|
||||
}
|
9
SpotifyAPI.Web/Models/Response/TracksResponse.cs
Normal file
9
SpotifyAPI.Web/Models/Response/TracksResponse.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class TracksResponse
|
||||
{
|
||||
public List<FullTrack> Tracks { get; private set; }
|
||||
}
|
||||
}
|
@ -51,6 +51,16 @@ namespace SpotifyAPI.Web
|
||||
|
||||
public static Uri PlaylistFollowers(string playlistId) => EUri($"playlists/{playlistId}/followers");
|
||||
|
||||
public static Uri Tracks() => EUri($"tracks");
|
||||
|
||||
public static Uri Track(string trackId) => EUri($"tracks/{trackId}");
|
||||
|
||||
public static Uri AudioAnalysis(string trackId) => EUri($"audio-analysis/{trackId}");
|
||||
|
||||
public static Uri AudioFeatures(string trackId) => EUri($"audio-features/{trackId}");
|
||||
|
||||
public static Uri AudioFeatures() => EUri($"audio-features");
|
||||
|
||||
private static Uri EUri(FormattableString path) => new Uri(path.ToString(_provider), UriKind.Relative);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user