diff --git a/SpotifyAPI.Example/WebControl.cs b/SpotifyAPI.Example/WebControl.cs index 0f6b7c57..5d7f88df 100644 --- a/SpotifyAPI.Example/WebControl.cs +++ b/SpotifyAPI.Example/WebControl.cs @@ -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 artists = new List() { "0daugAjUgbJSqdlyYNwIbT" }; - - Recommendations reco = _spotify.GetRecommendations(target:asd, artistSeed:artists); - RecommendationSeedGenres genres = _spotify.GetRecommendationSeedsGenres(); - authButton.Enabled = false; _profile = _spotify.GetPrivateProfile(); diff --git a/SpotifyAPI/SpotifyAPI.csproj b/SpotifyAPI/SpotifyAPI.csproj index 8d35cf74..65032259 100644 --- a/SpotifyAPI/SpotifyAPI.csproj +++ b/SpotifyAPI/SpotifyAPI.csproj @@ -58,6 +58,7 @@ + diff --git a/SpotifyAPI/Web/Enums/Scope.cs b/SpotifyAPI/Web/Enums/Scope.cs index 5e5d8ea6..0cbc90b3 100644 --- a/SpotifyAPI/Web/Enums/Scope.cs +++ b/SpotifyAPI/Web/Enums/Scope.cs @@ -39,6 +39,9 @@ namespace SpotifyAPI.Web.Enums UserFollowRead = 1024, [String("user-read-birthdate")] - UserReadBirthdate = 2048 + UserReadBirthdate = 2048, + + [String("user-top-read")] + UserTopRead = 4096 } } \ No newline at end of file diff --git a/SpotifyAPI/Web/Enums/TimeRangeType.cs b/SpotifyAPI/Web/Enums/TimeRangeType.cs new file mode 100644 index 00000000..468a8081 --- /dev/null +++ b/SpotifyAPI/Web/Enums/TimeRangeType.cs @@ -0,0 +1,20 @@ +using System; + +namespace SpotifyAPI.Web.Enums +{ + /// + /// Only one value allowed + /// + [Flags] + public enum TimeRangeType + { + [String("long_term")] + LongTerm = 1, + + [String("medium_term")] + MediumTerm = 2, + + [String("short_term")] + ShortTerm = 4 + } +} \ No newline at end of file diff --git a/SpotifyAPI/Web/SpotifyWebAPI.cs b/SpotifyAPI/Web/SpotifyWebAPI.cs index c51fdbcd..c7902e7e 100644 --- a/SpotifyAPI/Web/SpotifyWebAPI.cs +++ b/SpotifyAPI/Web/SpotifyWebAPI.cs @@ -1146,6 +1146,70 @@ namespace SpotifyAPI.Web #endregion Library + #region Personalization + + /// + /// Get the current user’s top tracks based on calculated affinity. + /// + /// 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). + /// The number of entities to return. Default: 20. Minimum: 1. Maximum: 50 + /// 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. + /// + /// AUTH NEEDED + public Paging GetUsersTopTracks(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0) + { + return DownloadData>(_builder.GetUsersTopTracks(timeRange, limit, offest)); + } + + /// + /// Get the current user’s top tracks based on calculated affinity asynchronously. + /// + /// 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). + /// The number of entities to return. Default: 20. Minimum: 1. Maximum: 50 + /// 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. + /// + /// AUTH NEEDED + public async Task> GetUsersTopTracksAsync(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0) + { + return await DownloadDataAsync>(_builder.GetUsersTopTracks(timeRange, limit, offest)); + } + + /// + /// Get the current user’s top artists based on calculated affinity. + /// + /// 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). + /// The number of entities to return. Default: 20. Minimum: 1. Maximum: 50 + /// 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. + /// + /// AUTH NEEDED + public Paging GetUsersTopArtists(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0) + { + return DownloadData>(_builder.GetUsersTopArtists(timeRange, limit, offest)); + } + + /// + /// Get the current user’s top artists based on calculated affinity asynchronously. + /// + /// 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). + /// The number of entities to return. Default: 20. Minimum: 1. Maximum: 50 + /// 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. + /// + /// AUTH NEEDED + public async Task> GetUsersTopArtistsAsync(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0) + { + return await DownloadDataAsync>(_builder.GetUsersTopArtists(timeRange, limit, offest)); + } + + #endregion + #region Playlists /// diff --git a/SpotifyAPI/Web/SpotifyWebBuilder.cs b/SpotifyAPI/Web/SpotifyWebBuilder.cs index 5106f4c0..27928c7f 100644 --- a/SpotifyAPI/Web/SpotifyWebBuilder.cs +++ b/SpotifyAPI/Web/SpotifyWebBuilder.cs @@ -545,6 +545,50 @@ namespace SpotifyAPI.Web #endregion Library + #region Personalization + + /// + /// Get the current user’s top tracks based on calculated affinity. + /// + /// 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). + /// The number of entities to return. Default: 20. Minimum: 1. Maximum: 50 + /// 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. + /// + /// AUTH NEEDED + 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(); + } + + /// + /// Get the current user’s top artists based on calculated affinity. + /// + /// 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). + /// The number of entities to return. Default: 20. Minimum: 1. Maximum: 50 + /// 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. + /// + /// AUTH NEEDED + 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 ///