Release 1.0.0.4: album artists, credits, artist genres, maintenance task
This commit is contained in:
1 parent
84e3ea34c8
commit
0dbf427ce1
17 files changed
+332
-14
No files matched your search
@@ -44,6 +44,8 @@ public sealed class YandexMusicClient
|
||||
private readonly SemaphoreSlim _genreLock = new(1, 1);
|
||||
private Dictionary<string, string>? _genreCache;
|
||||
private string _genreCacheLanguage = string.Empty;
|
||||
private readonly System.Collections.Concurrent.ConcurrentDictionary<long, string[]> _artistGenres = new();
|
||||
private readonly System.Collections.Concurrent.ConcurrentDictionary<long, List<CreditDto>> _credits = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="YandexMusicClient"/> class.
|
||||
@@ -168,6 +170,38 @@ public sealed class YandexMusicClient
|
||||
false,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
|
||||
/// <summary>Gets an artist's genre ids, cached per artist.</summary>
|
||||
public async Task<string[]> GetArtistGenresAsync(long artistId, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_artistGenres.TryGetValue(artistId, out var cached))
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
var artist = await GetArtistAsync(artistId, cancellationToken).ConfigureAwait(false);
|
||||
var genres = artist?.Genres.ToArray() ?? [];
|
||||
_artistGenres[artistId] = genres;
|
||||
return genres;
|
||||
}
|
||||
|
||||
/// <summary>Gets track credits (composers, lyricists, label), cached per track.</summary>
|
||||
public async Task<List<CreditDto>> GetTrackCreditsAsync(long trackId, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_credits.TryGetValue(trackId, out var cached))
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
var response = await GetJsonAsync<CreditsResponse>(
|
||||
string.Format(CultureInfo.InvariantCulture, "/tracks/{0}/credits", trackId),
|
||||
false,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var credits = response?.Result?.Credits ?? [];
|
||||
_credits[trackId] = credits;
|
||||
return credits;
|
||||
}
|
||||
|
||||
/// <summary>Gets similar artists and covers.</summary>
|
||||
public async Task<ArtistBriefDto?> GetArtistBriefAsync(long id, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user