Добавьте файлы проекта.
This commit is contained in:
71
YandexMusic.API/Models/Common/Cover/YCover.cs
Normal file
71
YandexMusic.API/Models/Common/Cover/YCover.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
8
YandexMusic.API/Models/Common/Cover/YCoverColor.cs
Normal file
8
YandexMusic.API/Models/Common/Cover/YCoverColor.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
7
YandexMusic.API/Models/Common/Cover/YCoverError.cs
Normal file
7
YandexMusic.API/Models/Common/Cover/YCoverError.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace YandexMusic.API.Models.Common.Cover
|
||||
{
|
||||
public class YCoverError : YCover
|
||||
{
|
||||
public string Error { get; set; }
|
||||
}
|
||||
}
|
||||
8
YandexMusic.API/Models/Common/Cover/YCoverImage.cs
Normal file
8
YandexMusic.API/Models/Common/Cover/YCoverImage.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
8
YandexMusic.API/Models/Common/Cover/YCoverMosaic.cs
Normal file
8
YandexMusic.API/Models/Common/Cover/YCoverMosaic.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
11
YandexMusic.API/Models/Common/Cover/YCoverPic.cs
Normal file
11
YandexMusic.API/Models/Common/Cover/YCoverPic.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
17
YandexMusic.API/Models/Common/Cover/YCoverType.cs
Normal file
17
YandexMusic.API/Models/Common/Cover/YCoverType.cs
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user