Добавьте файлы проекта.

This commit is contained in:
FrigaT
2026-04-10 12:12:33 +03:00
parent 9615cf42ee
commit 11d0b0d72f
383 changed files with 9661 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
namespace YandexMusic.API.Models.Common.Cover
{
public sealed class YCoverConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return typeof(YCover).IsAssignableFrom(objectType);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
return null;
JObject jObject = JObject.Load(reader);
YCover cover;
try
{
// Фиктивный тип, т.к. у такой обложки нет поля с типом
if (jObject["type"] == null)
jObject.Add("type", "color");
YCoverType type = jObject["error"] != null
? YCoverType.Error
: jObject["type"].ToObject<YCoverType>();
switch (type)
{
case YCoverType.Error:
cover = jObject.ToObject<YCoverError>();
break;
case YCoverType.Color:
cover = jObject.ToObject<YCoverColor>();
break;
case YCoverType.FromAlbumCover:
case YCoverType.FromArtistPhotos:
cover = jObject.ToObject<YCoverImage>();
break;
case YCoverType.Pic:
cover = jObject.ToObject<YCoverPic>();
break;
case YCoverType.Mosaic:
cover = jObject.ToObject<YCoverMosaic>();
break;
default:
cover = jObject.ToObject<YCover>();
break;
}
}
catch (Exception ex)
{
throw new Exception($"Ошибка десериализации типа \"{objectType.Name}\".", ex);
}
return cover;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
JObject cover = JObject.FromObject(value, serializer);
cover.WriteTo(writer);
}
}
public class YCover
{
public YCoverType Type { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace YandexMusic.API.Models.Common.Cover
{
public class YCoverColor : YCover
{
public string Uri { get; set; }
public string Color { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
namespace YandexMusic.API.Models.Common.Cover
{
public class YCoverError : YCover
{
public string Error { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace YandexMusic.API.Models.Common.Cover
{
public class YCoverImage : YCover
{
public string Prefix { get; set; }
public string Uri { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace YandexMusic.API.Models.Common.Cover
{
public class YCoverMosaic : YCover
{
public bool Custom { get; set; }
public List<string> ItemsUri { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
namespace YandexMusic.API.Models.Common.Cover
{
public class YCoverPic : YCover
{
public bool Custom { get; set; }
public string Dir { get; set; }
public bool IsCustom { get; set; }
public string Uri { get; set; }
public string Version { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
using System.Runtime.Serialization;
namespace YandexMusic.API.Models.Common.Cover
{
[JsonConverter(typeof(StringEnumConverter))]
public enum YCoverType
{
Color,
Error,
[EnumMember(Value = "from-artist-photos")]
FromArtistPhotos,
[EnumMember(Value = "from-album-cover")]
FromAlbumCover,
Mosaic,
Pic
}
}