diff --git a/YandexMusic.API/Models/Artist/YArtistBriefInfo.cs b/YandexMusic.API/Models/Artist/YArtistBriefInfo.cs index 376baf1..114c4f0 100644 --- a/YandexMusic.API/Models/Artist/YArtistBriefInfo.cs +++ b/YandexMusic.API/Models/Artist/YArtistBriefInfo.cs @@ -1,4 +1,3 @@ -using System.Text.Json.Serialization; using YandexMusic.API.Models.Album; using YandexMusic.API.Models.Common; using YandexMusic.API.Models.Common.Cover; @@ -11,7 +10,6 @@ public class YArtistBriefInfo { public YButton ActionButton { get; set; } public List Albums { get; set; } - [JsonConverter(typeof(YCoverConverter))] public List AllCovers { get; set; } public List AlsoAlbums { get; set; } public YArtist Artist { get; set; } diff --git a/YandexMusic.API/Models/Common/Cover/YCover.cs b/YandexMusic.API/Models/Common/Cover/YCover.cs index 174dd1d..c0a0678 100644 --- a/YandexMusic.API/Models/Common/Cover/YCover.cs +++ b/YandexMusic.API/Models/Common/Cover/YCover.cs @@ -1,33 +1,7 @@ -using System.Text.Json; using System.Text.Json.Serialization; namespace YandexMusic.API.Models.Common.Cover; -public class YCoverConverter : JsonConverter -{ - public override YCover? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - if (reader.TokenType != JsonTokenType.StartObject) return null; - using var doc = JsonDocument.ParseValue(ref reader); - var root = doc.RootElement; - var type = root.TryGetProperty("type", out var t) ? t.GetString() : null; - if (root.TryGetProperty("error", out _)) type = "error"; - - return type switch - { - "color" => JsonSerializer.Deserialize(root.GetRawText(), options), - "error" => JsonSerializer.Deserialize(root.GetRawText(), options), - "from-artist-photos" or "from-album-cover" => JsonSerializer.Deserialize(root.GetRawText(), options), - "pic" => JsonSerializer.Deserialize(root.GetRawText(), options), - "mosaic" => JsonSerializer.Deserialize(root.GetRawText(), options), - _ => new YCover() { Type = YCoverType.Error } - }; - } - - public override void Write(Utf8JsonWriter writer, YCover value, JsonSerializerOptions options) - => JsonSerializer.Serialize(writer, value, options); -} - [JsonConverter(typeof(YCoverConverter))] public class YCover { diff --git a/YandexMusic.API/Models/Common/Cover/YCoverConverter.cs b/YandexMusic.API/Models/Common/Cover/YCoverConverter.cs new file mode 100644 index 0000000..79c4acf --- /dev/null +++ b/YandexMusic.API/Models/Common/Cover/YCoverConverter.cs @@ -0,0 +1,29 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace YandexMusic.API.Models.Common.Cover; + +public class YCoverConverter : JsonConverter +{ + public override YCover? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + if (reader.TokenType != JsonTokenType.StartObject) return null; + using var doc = JsonDocument.ParseValue(ref reader); + var root = doc.RootElement; + var type = root.TryGetProperty("type", out var t) ? t.GetString() : null; + if (root.TryGetProperty("error", out _)) type = "error"; + + return type switch + { + "color" => JsonSerializer.Deserialize(root.GetRawText(), options), + "error" => JsonSerializer.Deserialize(root.GetRawText(), options), + "from-artist-photos" or "from-album-cover" => JsonSerializer.Deserialize(root.GetRawText(), options), + "pic" => JsonSerializer.Deserialize(root.GetRawText(), options), + "mosaic" => JsonSerializer.Deserialize(root.GetRawText(), options), + _ => new YCover() { Type = YCoverType.Error } + }; + } + + public override void Write(Utf8JsonWriter writer, YCover value, JsonSerializerOptions options) + => JsonSerializer.Serialize(writer, value, options); +}