mirror of
https://github.com/Sarsoo/IF.Lastfm.git
synced 2024-10-17 07:13:09 +01:00
Add tag.GetTopAlbumsCommand
This commit is contained in:
parent
ef0b0ff9c9
commit
b0eea4b304
51
src/IF.Lastfm.Core/Api/Commands/Tag/GetTopAlbumsCommand.cs
Normal file
51
src/IF.Lastfm.Core/Api/Commands/Tag/GetTopAlbumsCommand.cs
Normal file
@ -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.getTopAlbums")]
|
||||||
|
internal class GetTopAlbumsCommand: GetAsyncCommandBase<PageResponse<LastAlbum>>
|
||||||
|
{
|
||||||
|
public string TagName { get; set; }
|
||||||
|
|
||||||
|
public GetTopAlbumsCommand(ILastAuth auth, string tagName) : base(auth)
|
||||||
|
{
|
||||||
|
TagName = tagName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetParameters()
|
||||||
|
{
|
||||||
|
Parameters.Add("tag", TagName);
|
||||||
|
AddPagingParameters();
|
||||||
|
DisableCaching();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async override Task<PageResponse<LastAlbum>> HandleResponse(HttpResponseMessage response)
|
||||||
|
{
|
||||||
|
var json = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
LastResponseStatus status;
|
||||||
|
if (LastFm.IsResponseValid(json, out status) && response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
var jtoken = JsonConvert.DeserializeObject<JToken>(json);
|
||||||
|
var resultsToken = jtoken.SelectToken("topalbums");
|
||||||
|
var itemsToken = resultsToken.SelectToken("album");
|
||||||
|
|
||||||
|
return PageResponse<LastAlbum>.CreateSuccessResponse(itemsToken, resultsToken, LastAlbum.ParseJToken, LastPageResultsType.Attr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return LastResponse.CreateErrorResponse<PageResponse<LastAlbum>>(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,5 +8,6 @@ public interface ITagApi
|
|||||||
{
|
{
|
||||||
Task<PageResponse<LastTag>> GetSimilarAsync(string tagName);
|
Task<PageResponse<LastTag>> GetSimilarAsync(string tagName);
|
||||||
Task<LastResponse<LastTag>> GetInfoAsync(string tagName);
|
Task<LastResponse<LastTag>> GetInfoAsync(string tagName);
|
||||||
|
Task<PageResponse<LastAlbum>> GetTopAlbumsAsync(string tagName,int page,int itemsPerPage);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -43,6 +43,20 @@ public Task<LastResponse<LastTag>> GetInfoAsync(string tagName)
|
|||||||
return command.ExecuteAsync();
|
return command.ExecuteAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the top albums tagged by this tag, ordered by tag count.
|
||||||
|
/// </summary>
|
||||||
|
public Task<PageResponse<LastAlbum>> GetTopAlbumsAsync(string tagName, int page=1, int itemsPerPage= LastFm.DefaultPageLength)
|
||||||
|
{
|
||||||
|
var command = new GetTopAlbumsCommand(Auth, tagName)
|
||||||
|
{
|
||||||
|
Page = page,
|
||||||
|
Count = itemsPerPage
|
||||||
|
};
|
||||||
|
|
||||||
|
return command.ExecuteAsync();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fetches the top global tags on Last.fm, sorted by popularity (number of times used).
|
/// Fetches the top global tags on Last.fm, sorted by popularity (number of times used).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -65,6 +65,7 @@
|
|||||||
<Compile Include="Api\Commands\Library\RemoveTrackCommand.cs" />
|
<Compile Include="Api\Commands\Library\RemoveTrackCommand.cs" />
|
||||||
<Compile Include="Api\Commands\Tag\GetInfoCommand.cs" />
|
<Compile Include="Api\Commands\Tag\GetInfoCommand.cs" />
|
||||||
<Compile Include="Api\Commands\Tag\GetSimilarCommand.cs" />
|
<Compile Include="Api\Commands\Tag\GetSimilarCommand.cs" />
|
||||||
|
<Compile Include="Api\Commands\Tag\GetTopAlbumsCommand.cs" />
|
||||||
<Compile Include="Api\Commands\Tag\GetTopTagsCommand.cs" />
|
<Compile Include="Api\Commands\Tag\GetTopTagsCommand.cs" />
|
||||||
<Compile Include="Api\Commands\Track\ScrobbleCommand.cs" />
|
<Compile Include="Api\Commands\Track\ScrobbleCommand.cs" />
|
||||||
<Compile Include="Api\Commands\Track\UpdateNowPlayingCommand.cs" />
|
<Compile Include="Api\Commands\Track\UpdateNowPlayingCommand.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user