Skip to content

Commit ca4bd1e

Browse files
committed
Added Top artists/tracks
1 parent 8c0d765 commit ca4bd1e

File tree

6 files changed

+134
-11
lines changed

6 files changed

+134
-11
lines changed

SpotifyAPI.Example/WebControl.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public WebControl()
3131
{
3232
RedirectUri = "http://localhost:8000",
3333
ClientId = "26d287105e31491889f3cd293d85bfea",
34-
Scope = Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibraryRead | Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate,
34+
Scope = Scope.UserReadPrivate | Scope.UserReadEmail | Scope.PlaylistReadPrivate | Scope.UserLibraryRead | Scope.UserReadPrivate | Scope.UserFollowRead | Scope.UserReadBirthdate | Scope.UserTopRead,
3535
State = "XSS"
3636
};
3737
_auth.OnResponseReceivedEvent += _auth_OnResponseReceivedEvent;
@@ -69,15 +69,6 @@ private async void InitialSetup()
6969
return;
7070
}
7171

72-
TuneableTrack asd = new TuneableTrack
73-
{
74-
Acousticness = 0.0029f
75-
};
76-
List<string> artists = new List<string>() { "0daugAjUgbJSqdlyYNwIbT" };
77-
78-
Recommendations reco = _spotify.GetRecommendations(target:asd, artistSeed:artists);
79-
RecommendationSeedGenres genres = _spotify.GetRecommendationSeedsGenres();
80-
8172
authButton.Enabled = false;
8273
_profile = _spotify.GetPrivateProfile();
8374

SpotifyAPI/SpotifyAPI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
</Compile>
5959
<Compile Include="Local\Models\SpotifyUri.cs" />
6060
<Compile Include="Local\VolumeMixerControl.cs" />
61+
<Compile Include="Web\Enums\TimeRangeType.cs" />
6162
<Compile Include="Web\IClient.cs" />
6263
<Compile Include="Local\Models\CFID.cs" />
6364
<Compile Include="Local\Enums\AlbumArtSize.cs" />

SpotifyAPI/Web/Enums/Scope.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public enum Scope
3939
UserFollowRead = 1024,
4040

4141
[String("user-read-birthdate")]
42-
UserReadBirthdate = 2048
42+
UserReadBirthdate = 2048,
43+
44+
[String("user-top-read")]
45+
UserTopRead = 4096
4346
}
4447
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
3+
namespace SpotifyAPI.Web.Enums
4+
{
5+
/// <summary>
6+
/// Only one value allowed
7+
/// </summary>
8+
[Flags]
9+
public enum TimeRangeType
10+
{
11+
[String("long_term")]
12+
LongTerm = 1,
13+
14+
[String("medium_term")]
15+
MediumTerm = 2,
16+
17+
[String("short_term")]
18+
ShortTerm = 4
19+
}
20+
}

SpotifyAPI/Web/SpotifyWebAPI.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,70 @@ public async Task<ListResponse<Boolean>> CheckSavedAlbumsAsync(List<string> ids)
11461146

11471147
#endregion Library
11481148

1149+
#region Personalization
1150+
1151+
/// <summary>
1152+
/// Get the current user’s top tracks based on calculated affinity.
1153+
/// </summary>
1154+
/// <param name="timeRange">Over what time frame the affinities are computed.
1155+
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
1156+
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
1157+
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
1158+
/// <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>
1159+
/// <returns></returns>
1160+
/// <remarks>AUTH NEEDED</remarks>
1161+
public Paging<FullTrack> GetUsersTopTracks(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0)
1162+
{
1163+
return DownloadData<Paging<FullTrack>>(_builder.GetUsersTopTracks(timeRange, limit, offest));
1164+
}
1165+
1166+
/// <summary>
1167+
/// Get the current user’s top tracks based on calculated affinity asynchronously.
1168+
/// </summary>
1169+
/// <param name="timeRange">Over what time frame the affinities are computed.
1170+
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
1171+
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
1172+
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
1173+
/// <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>
1174+
/// <returns></returns>
1175+
/// <remarks>AUTH NEEDED</remarks>
1176+
public async Task<Paging<FullTrack>> GetUsersTopTracksAsync(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0)
1177+
{
1178+
return await DownloadDataAsync<Paging<FullTrack>>(_builder.GetUsersTopTracks(timeRange, limit, offest));
1179+
}
1180+
1181+
/// <summary>
1182+
/// Get the current user’s top artists based on calculated affinity.
1183+
/// </summary>
1184+
/// <param name="timeRange">Over what time frame the affinities are computed.
1185+
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
1186+
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
1187+
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
1188+
/// <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>
1189+
/// <returns></returns>
1190+
/// <remarks>AUTH NEEDED</remarks>
1191+
public Paging<FullArtist> GetUsersTopArtists(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0)
1192+
{
1193+
return DownloadData<Paging<FullArtist>>(_builder.GetUsersTopArtists(timeRange, limit, offest));
1194+
}
1195+
1196+
/// <summary>
1197+
/// Get the current user’s top artists based on calculated affinity asynchronously.
1198+
/// </summary>
1199+
/// <param name="timeRange">Over what time frame the affinities are computed.
1200+
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
1201+
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
1202+
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
1203+
/// <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>
1204+
/// <returns></returns>
1205+
/// <remarks>AUTH NEEDED</remarks>
1206+
public async Task<Paging<FullArtist>> GetUsersTopArtistsAsync(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0)
1207+
{
1208+
return await DownloadDataAsync<Paging<FullArtist>>(_builder.GetUsersTopArtists(timeRange, limit, offest));
1209+
}
1210+
1211+
#endregion
1212+
11491213
#region Playlists
11501214

11511215
/// <summary>

SpotifyAPI/Web/SpotifyWebBuilder.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,50 @@ public string CheckSavedAlbums(List<string> ids)
545545

546546
#endregion Library
547547

548+
#region Personalization
549+
550+
/// <summary>
551+
/// Get the current user’s top tracks based on calculated affinity.
552+
/// </summary>
553+
/// <param name="timeRange">Over what time frame the affinities are computed.
554+
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
555+
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
556+
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
557+
/// <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>
558+
/// <returns></returns>
559+
/// <remarks>AUTH NEEDED</remarks>
560+
public string GetUsersTopTracks(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0)
561+
{
562+
limit = Math.Min(50, limit);
563+
StringBuilder builder = new StringBuilder($"{APIBase}/me/top/tracks");
564+
builder.Append("?limit=" + limit);
565+
builder.Append("&offset=" + offest);
566+
builder.Append("&time_range=" + timeRange.GetStringAttribute(""));
567+
return builder.ToString();
568+
}
569+
570+
/// <summary>
571+
/// Get the current user’s top artists based on calculated affinity.
572+
/// </summary>
573+
/// <param name="timeRange">Over what time frame the affinities are computed.
574+
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
575+
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
576+
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
577+
/// <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>
578+
/// <returns></returns>
579+
/// <remarks>AUTH NEEDED</remarks>
580+
public string GetUsersTopArtists(TimeRangeType timeRange = TimeRangeType.MediumTerm, int limit = 20, int offest = 0)
581+
{
582+
limit = Math.Min(50, limit);
583+
StringBuilder builder = new StringBuilder($"{APIBase}/me/top/artists");
584+
builder.Append("?limit=" + limit);
585+
builder.Append("&offset=" + offest);
586+
builder.Append("&time_range=" + timeRange.GetStringAttribute(""));
587+
return builder.ToString();
588+
}
589+
590+
#endregion
591+
548592
#region Playlists
549593

550594
/// <summary>

0 commit comments

Comments
 (0)