Проведен аудит. Добавлено переключение треков
This commit is contained in:
@@ -35,6 +35,21 @@ public class YandexMusicService
|
||||
return await Api.Playlist.GetAsync(ownerUid, kind);
|
||||
}
|
||||
|
||||
public async Task<YandexPlaylistData?> GetPlaylistDataAsync(ApplicationUser user, string ownerUid, string kind)
|
||||
{
|
||||
var playlist = await GetPlaylistAsync(user, ownerUid, kind);
|
||||
return playlist == null ? null : MapToPlaylistData(playlist);
|
||||
}
|
||||
|
||||
public async Task<(List<YPlaylist>? OwnPlaylists, string? AccountUid)> GetOwnFavoritesAsync(ApplicationUser user)
|
||||
{
|
||||
await AuthorizeIfNot(user);
|
||||
var favorites = await Api.Playlist.FavoritesAsync();
|
||||
var accountUid = _yandexApiService.Client.Account?.Uid;
|
||||
var ownPlaylists = favorites?.Where(p => p.Owner?.Uid == accountUid).ToList();
|
||||
return (ownPlaylists, accountUid);
|
||||
}
|
||||
|
||||
public async Task<YPlaylist?> CreatePlaylistAsync(ApplicationUser user, string title)
|
||||
{
|
||||
await AuthorizeIfNot(user);
|
||||
@@ -339,4 +354,24 @@ public class YandexMusicService
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static YandexPlaylistData MapToPlaylistData(YPlaylist playlist) => new()
|
||||
{
|
||||
Title = playlist.Title,
|
||||
Description = playlist.Description,
|
||||
Tracks = playlist.Tracks.Select(t => new YandexTrack
|
||||
{
|
||||
TrackId = t.Track.Id,
|
||||
Title = t.Track.Title,
|
||||
Artists = t.Track.Artists.Select(a => new YandexArtist
|
||||
{
|
||||
Id = a.Id,
|
||||
Name = a.Name,
|
||||
CoverUrl = a.Cover.GetUrl(),
|
||||
Description = a.Description?.Text ?? string.Empty,
|
||||
}).ToList(),
|
||||
DurationMs = (int)(t.Track?.DurationMs ?? 0),
|
||||
CoverUri = t.Track?.CoverUri ?? ""
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user