Added Top artists/tracks

This commit is contained in:
Johnny @PC 2016-04-01 14:08:06 +02:00
parent 8c0d765eef
commit ca4bd1edaf
6 changed files with 134 additions and 11 deletions

View File

@ -31,7 +31,7 @@ namespace SpotifyAPI.Example
{
RedirectUri = "http://localhost:8000",
ClientId = "26d287105e31491889f3cd293d85bfea",
Scope = Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibraryRead | Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate,
Scope = Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibraryRead | Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate | Scope.UserTopRead,
State = "XSS"
};
_auth.OnResponseReceivedEvent += _auth_OnResponseReceivedEvent;
@ -69,15 +69,6 @@ namespace SpotifyAPI.Example
return;
}
TuneableTrack asd = new TuneableTrack
{
Acousticness = 0.0029f
};
List<string> artists = new List<string>() { "0daugAjUgbJSqdlyYNwIbT" };
Recommendations reco = _spotify.GetRecommendations(target:asd, artistSeed:artists);
RecommendationSeedGenres genres = _spotify.GetRecommendationSeedsGenres();
authButton.Enabled = false;
_profile = _spotify.GetPrivateProfile();

View File

@ -58,6 +58,7 @@
</Compile>
<Compile Include="Local\Models\SpotifyUri.cs" />
<Compile Include="Local\VolumeMixerControl.cs" />
<Compile Include="Web\Enums\TimeRangeType.cs" />
<Compile Include="Web\IClient.cs" />
<Compile Include="Local\Models\CFID.cs" />
<Compile Include="Local\Enums\AlbumArtSize.cs" />

View File

@ -39,6 +39,9 @@ namespace SpotifyAPI.Web.Enums
UserFollowRead = 1024,
[String("user-read-birthdate")]
UserReadBirthdate = 2048
UserReadBirthdate = 2048,
[String("user-top-read")]
UserTopRead = 4096
}
}

View File

@ -0,0 +1,20 @@
using System;
namespace SpotifyAPI.Web.Enums
{
/// <summary>
/// Only one value allowed
/// </summary>
[Flags]
public enum TimeRangeType
{
[String("long_term")]
LongTerm = 1,
[String("medium_term")]
MediumTerm = 2,
[String("short_term")]
ShortTerm = 4
}
}

View File

@ -1146,6 +1146,70 @@ namespace SpotifyAPI.Web
#endregion Library
#region Personalization
/// <summary>
/// Get the current users top tracks based on calculated affinity.
/// </summary>
/// <param name="timeRange">Over what time frame the affinities are computed.
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
/// <param name="offest">The index of the first entity to return. Default: 0 (i.e., the first track). Use with limit to get the next set of entities.</param>
/// <returns></returns>
/// <remarks>AUTH NEEDED</remarks>
public Paging<FullTrack> GetUsersTopTracks(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0)
{
return DownloadData<Paging<FullTrack>>(_builder.GetUsersTopTracks(timeRange, limit, offest));
}
/// <summary>
/// Get the current users top tracks based on calculated affinity asynchronously.
/// </summary>
/// <param name="timeRange">Over what time frame the affinities are computed.
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
/// <param name="offest">The index of the first entity to return. Default: 0 (i.e., the first track). Use with limit to get the next set of entities.</param>
/// <returns></returns>
/// <remarks>AUTH NEEDED</remarks>
public async Task<Paging<FullTrack>> GetUsersTopTracksAsync(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0)
{
return await DownloadDataAsync<Paging<FullTrack>>(_builder.GetUsersTopTracks(timeRange, limit, offest));
}
/// <summary>
/// Get the current users top artists based on calculated affinity.
/// </summary>
/// <param name="timeRange">Over what time frame the affinities are computed.
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
/// <param name="offest">The index of the first entity to return. Default: 0 (i.e., the first track). Use with limit to get the next set of entities.</param>
/// <returns></returns>
/// <remarks>AUTH NEEDED</remarks>
public Paging<FullArtist> GetUsersTopArtists(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0)
{
return DownloadData<Paging<FullArtist>>(_builder.GetUsersTopArtists(timeRange, limit, offest));
}
/// <summary>
/// Get the current users top artists based on calculated affinity asynchronously.
/// </summary>
/// <param name="timeRange">Over what time frame the affinities are computed.
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
/// <param name="offest">The index of the first entity to return. Default: 0 (i.e., the first track). Use with limit to get the next set of entities.</param>
/// <returns></returns>
/// <remarks>AUTH NEEDED</remarks>
public async Task<Paging<FullArtist>> GetUsersTopArtistsAsync(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0)
{
return await DownloadDataAsync<Paging<FullArtist>>(_builder.GetUsersTopArtists(timeRange, limit, offest));
}
#endregion
#region Playlists
/// <summary>

View File

@ -545,6 +545,50 @@ namespace SpotifyAPI.Web
#endregion Library
#region Personalization
/// <summary>
/// Get the current users top tracks based on calculated affinity.
/// </summary>
/// <param name="timeRange">Over what time frame the affinities are computed.
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
/// <param name="offest">The index of the first entity to return. Default: 0 (i.e., the first track). Use with limit to get the next set of entities.</param>
/// <returns></returns>
/// <remarks>AUTH NEEDED</remarks>
public string GetUsersTopTracks(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0)
{
limit = Math.Min(50, limit);
StringBuilder builder = new StringBuilder($"{APIBase}/me/top/tracks");
builder.Append("?limit=" + limit);
builder.Append("&offset=" + offest);
builder.Append("&time_range=" + timeRange.GetStringAttribute(""));
return builder.ToString();
}
/// <summary>
/// Get the current users top artists based on calculated affinity.
/// </summary>
/// <param name="timeRange">Over what time frame the affinities are computed.
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
/// <param name="offest">The index of the first entity to return. Default: 0 (i.e., the first track). Use with limit to get the next set of entities.</param>
/// <returns></returns>
/// <remarks>AUTH NEEDED</remarks>
public string GetUsersTopArtists(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0)
{
limit = Math.Min(50, limit);
StringBuilder builder = new StringBuilder($"{APIBase}/me/top/artists");
builder.Append("?limit=" + limit);
builder.Append("&offset=" + offest);
builder.Append("&time_range=" + timeRange.GetStringAttribute(""));
return builder.ToString();
}
#endregion
#region Playlists
/// <summary>