using YandexMusic.API.Models.Artist; using YandexMusic.API.Models.Common; using YandexMusic.API.Models.Common.Cover; using YandexMusic.API.Models.Track; namespace YandexMusic.API.Models.Album { public sealed class YLabelConverter : JsonConverter { public override bool CanConvert(Type objectType) { throw new NotImplementedException(); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.TokenType == JsonToken.Null) return null; JArray jArray = JArray.Load(reader); JTokenType tokenType = jArray.FirstOrDefault()?.Type ?? JTokenType.String; object label; try { label = tokenType switch { JTokenType.Object => jArray.ToObject>(), _ => jArray.ToObject>() }; } catch (Exception ex) { throw new Exception($"Ошибка десериализации типа \"{objectType.Name}\".", ex); } return label; } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { JArray array = JArray.FromObject(value); array.WriteTo(writer); } } public class YAlbum : YBaseModel { public YButton ActionButton { get; set; } public List Artists { get; set; } public bool Available { get; set; } public bool AvailableForMobile { get; set; } public List AvailableForOptions { get; set; } public bool AvailableForPremiumUsers { get; set; } public bool AvailablePartially { get; set; } public string BackgroundImageUrl { get; set; } public string BackgroundVideoUrl { get; set; } public List Bests { get; set; } public List Buy { get; set; } public bool ChildContent { get; set; } public string ContentWarning { get; set; } public string CoverUri { get; set; } [JsonConverter(typeof(YCoverConverter))] public YCover Cover { get; set; } public YCustomWave CustomWave { get; set; } public YDerivedColors DerivedColors { get; set; } public string Description { get; set; } public List Disclaimers { get; set; } public List Duplicates { get; set; } public bool HasTrailer { get; set; } public string Genre { get; set; } public string Id { get; set; } [JsonConverter(typeof(YLabelConverter))] public dynamic Labels { get; set; } public int LikesCount { get; set; } public bool ListeningFinished { get; set; } public string MetaTagId { get; set; } public YMetaType MetaType { get; set; } public string OgImage { get; set; } public YPager Pager { get; set; } public List Prerolls { get; set; } public bool Recent { get; set; } public DateTime ReleaseDate { get; set; } public string ShortDescription { get; set; } public YSortOrder SortOrder { get; set; } public string StorageDir { get; set; } public string Title { get; set; } public int TrackCount { get; set; } public YTrackPosition TrackPosition { get; set; } public YTrailer Trailer { get; set; } public string Type { get; set; } public string Version { get; set; } public bool VeryImportant { get; set; } public List> Volumes { get; set; } public int Year { get; set; } } }