diff --git a/src/IF.Lastfm.Core/Api/Commands/Tag/GetTopArtistsCommand.cs b/src/IF.Lastfm.Core/Api/Commands/Tag/GetTopArtistsCommand.cs index 6c2b565..175c42a 100644 --- a/src/IF.Lastfm.Core/Api/Commands/Tag/GetTopArtistsCommand.cs +++ b/src/IF.Lastfm.Core/Api/Commands/Tag/GetTopArtistsCommand.cs @@ -12,12 +12,12 @@ namespace IF.Lastfm.Core.Api.Commands.Tag { - [ApiMethodName("tag.getTopArtists")] - internal class GetTopArtistsCommand: GetAsyncCommandBase> + [ApiMethodName("tag.getTopTracks")] + internal class GetTopTracksCommand: GetAsyncCommandBase> { public string TagName { get; set; } - public GetTopArtistsCommand(ILastAuth auth, string tagName) : base(auth) + public GetTopTracksCommand(ILastAuth auth, string tagName) : base(auth) { TagName = tagName; } @@ -29,7 +29,7 @@ public override void SetParameters() DisableCaching(); } - public async override Task> HandleResponse(HttpResponseMessage response) + public async override Task> HandleResponse(HttpResponseMessage response) { var json = await response.Content.ReadAsStringAsync(); @@ -37,14 +37,14 @@ public async override Task> HandleResponse(HttpResponse if (LastFm.IsResponseValid(json, out status) && response.IsSuccessStatusCode) { var jtoken = JsonConvert.DeserializeObject(json); - var resultsToken = jtoken.SelectToken("topartists"); - var itemsToken = resultsToken.SelectToken("artist"); + var resultsToken = jtoken.SelectToken("toptracks"); + var itemsToken = resultsToken.SelectToken("track"); - return PageResponse.CreateSuccessResponse(itemsToken, resultsToken, LastArtist.ParseJToken, LastPageResultsType.Attr); + return PageResponse.CreateSuccessResponse(itemsToken, resultsToken, LastTrack.ParseJToken, LastPageResultsType.Attr); } else { - return LastResponse.CreateErrorResponse>(status); + return LastResponse.CreateErrorResponse>(status); } } } diff --git a/src/IF.Lastfm.Core/Api/Commands/Tag/GetTopTracksCommand.cs b/src/IF.Lastfm.Core/Api/Commands/Tag/GetTopTracksCommand.cs new file mode 100644 index 0000000..6c2b565 --- /dev/null +++ b/src/IF.Lastfm.Core/Api/Commands/Tag/GetTopTracksCommand.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using IF.Lastfm.Core.Api.Enums; +using IF.Lastfm.Core.Api.Helpers; +using IF.Lastfm.Core.Objects; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace IF.Lastfm.Core.Api.Commands.Tag +{ + [ApiMethodName("tag.getTopArtists")] + internal class GetTopArtistsCommand: GetAsyncCommandBase> + { + public string TagName { get; set; } + + public GetTopArtistsCommand(ILastAuth auth, string tagName) : base(auth) + { + TagName = tagName; + } + + public override void SetParameters() + { + Parameters.Add("tag", TagName); + AddPagingParameters(); + DisableCaching(); + } + + public async override Task> HandleResponse(HttpResponseMessage response) + { + var json = await response.Content.ReadAsStringAsync(); + + LastResponseStatus status; + if (LastFm.IsResponseValid(json, out status) && response.IsSuccessStatusCode) + { + var jtoken = JsonConvert.DeserializeObject(json); + var resultsToken = jtoken.SelectToken("topartists"); + var itemsToken = resultsToken.SelectToken("artist"); + + return PageResponse.CreateSuccessResponse(itemsToken, resultsToken, LastArtist.ParseJToken, LastPageResultsType.Attr); + } + else + { + return LastResponse.CreateErrorResponse>(status); + } + } + } +} diff --git a/src/IF.Lastfm.Core/Api/TagApi.cs b/src/IF.Lastfm.Core/Api/TagApi.cs index 20e8554..6113106 100644 --- a/src/IF.Lastfm.Core/Api/TagApi.cs +++ b/src/IF.Lastfm.Core/Api/TagApi.cs @@ -73,6 +73,21 @@ public Task> GetTopArtistsAsync(string tagName, int pag return command.ExecuteAsync(); } + /// + /// Get the top artists tagged by this tag, ordered by tag count. + /// + public Task> GetTopTracksAsync(string tagName, int page = 1, int itemsPerPage = LastFm.DefaultPageLength) + { + var command = new GetTopTracksCommand(Auth, tagName) + { + HttpClient = HttpClient, + Page = page, + Count = itemsPerPage + }; + + return command.ExecuteAsync(); + } + /// /// Fetches the top global tags on Last.fm, sorted by popularity (number of times used). /// diff --git a/src/IF.Lastfm.Core/IF.Lastfm.Core.csproj b/src/IF.Lastfm.Core/IF.Lastfm.Core.csproj index 0bd9468..710009e 100644 --- a/src/IF.Lastfm.Core/IF.Lastfm.Core.csproj +++ b/src/IF.Lastfm.Core/IF.Lastfm.Core.csproj @@ -68,6 +68,7 @@ +