Обнновлено до .net10

This commit is contained in:
FrigaT
2026-04-10 15:05:32 +03:00
parent 11d0b0d72f
commit 8444fc5f8e
386 changed files with 6361 additions and 7164 deletions

View File

@@ -1,98 +1,59 @@
using System.Text.Json.Serialization;
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
namespace YandexMusic.API.Models.Album;
/// <summary>Модель альбома.</summary>
public class YAlbum : YBaseModel
{
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<List<YLabel>>(),
_ => jArray.ToObject<List<string>>()
};
}
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<YArtist> Artists { get; set; }
public bool Available { get; set; }
public bool AvailableForMobile { get; set; }
public List<string> 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<string> Bests { get; set; }
public List<string> 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<string> Disclaimers { get; set; }
public List<YAlbum> 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<YPrerolls> 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<List<YTrack>> Volumes { get; set; }
public int Year { get; set; }
}
public YButton ActionButton { get; set; }
public List<YArtist> Artists { get; set; }
public bool Available { get; set; }
public bool AvailableForMobile { get; set; }
public List<string> 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<string> Bests { get; set; }
public List<string> 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<string> Disclaimers { get; set; }
public List<YAlbum> 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<YPrerolls> 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<List<YTrack>> Volumes { get; set; }
public int Year { get; set; }
}

View File

@@ -0,0 +1,32 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using YandexMusic.API.Models.Common;
namespace YandexMusic.API.Models.Album;
/// <summary>Конвертер для поля Labels, которое может быть списком строк или объектов.</summary>
public sealed class YLabelConverter : JsonConverter<object>
{
public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartArray)
throw new JsonException("Ожидается массив");
var list = new List<object>();
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndArray) break;
if (reader.TokenType == JsonTokenType.String)
list.Add(reader.GetString()!);
else if (reader.TokenType == JsonTokenType.StartObject)
{
var label = JsonSerializer.Deserialize<YLabel>(ref reader, options);
list.Add(label!);
}
}
return list;
}
public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
=> JsonSerializer.Serialize(writer, value, options);
}