Обнновлено до .net10
This commit is contained in:
@@ -1,54 +1,8 @@
|
||||
namespace YandexMusic.API.Models.Radio.Restriction
|
||||
namespace YandexMusic.API.Models.Radio.Restriction;
|
||||
|
||||
|
||||
public class YRestriction
|
||||
{
|
||||
public sealed class YRestrictionConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return typeof(YRestriction).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);
|
||||
YRestriction restriction;
|
||||
|
||||
try
|
||||
{
|
||||
YRestrictionType type = jObject["type"].ToObject<YRestrictionType>();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case YRestrictionType.Enum:
|
||||
restriction = jObject.ToObject<YRestrictionEnum>();
|
||||
break;
|
||||
case YRestrictionType.DiscreteScale:
|
||||
restriction = jObject.ToObject<YRestrictionDiscreteScale>();
|
||||
break;
|
||||
default:
|
||||
restriction = jObject.ToObject<YRestriction>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"Ошибка десериализации типа \"{objectType.Name}\".", ex);
|
||||
}
|
||||
|
||||
return restriction;
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class YRestriction
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public YRestrictionType Type { get; set; }
|
||||
}
|
||||
public string Name { get; set; }
|
||||
public YRestrictionType Type { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace YandexMusic.API.Models.Radio.Restriction;
|
||||
|
||||
/// <summary>Конвертер для ограничений радиостанции (дискретная шкала или перечисление).</summary>
|
||||
public class YRestrictionConverter : JsonConverter<YRestriction>
|
||||
{
|
||||
public override YRestriction? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.StartObject)
|
||||
throw new JsonException("Ожидается объект ограничения");
|
||||
|
||||
using var doc = JsonDocument.ParseValue(ref reader);
|
||||
var root = doc.RootElement;
|
||||
|
||||
var typeProp = root.GetProperty("type");
|
||||
var typeStr = typeProp.GetString();
|
||||
if (!Enum.TryParse<YRestrictionType>(typeStr, true, out var restrictionType))
|
||||
throw new JsonException($"Неизвестный тип ограничения: {typeStr}");
|
||||
|
||||
var rawText = root.GetRawText();
|
||||
|
||||
return restrictionType switch
|
||||
{
|
||||
YRestrictionType.Enum => JsonSerializer.Deserialize<YRestrictionEnum>(rawText, options),
|
||||
YRestrictionType.DiscreteScale => JsonSerializer.Deserialize<YRestrictionDiscreteScale>(rawText, options),
|
||||
_ => JsonSerializer.Deserialize<YRestriction>(rawText, options)
|
||||
};
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, YRestriction value, JsonSerializerOptions options)
|
||||
{
|
||||
JsonSerializer.Serialize(writer, value, options);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace YandexMusic.API.Models.Radio.Restriction
|
||||
namespace YandexMusic.API.Models.Radio.Restriction;
|
||||
|
||||
public class YRestrictionDiscreteScale : YRestriction
|
||||
{
|
||||
public class YRestrictionDiscreteScale : YRestriction
|
||||
{
|
||||
public YRestrictionValue<int> Min { get; set; }
|
||||
public YRestrictionValue<int> Max { get; set; }
|
||||
}
|
||||
public YRestrictionValue<int> Min { get; set; }
|
||||
public YRestrictionValue<int> Max { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace YandexMusic.API.Models.Radio.Restriction
|
||||
namespace YandexMusic.API.Models.Radio.Restriction;
|
||||
|
||||
public class YRestrictionEnum : YRestriction
|
||||
{
|
||||
public class YRestrictionEnum : YRestriction
|
||||
{
|
||||
public List<YRestrictionValue<string>> PossibleValues { get; set; }
|
||||
}
|
||||
public List<YRestrictionValue<string>> PossibleValues { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace YandexMusic.API.Models.Radio.Restriction
|
||||
namespace YandexMusic.API.Models.Radio.Restriction;
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public enum YRestrictionType
|
||||
{
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum YRestrictionType
|
||||
{
|
||||
[EnumMember(Value = "discrete-scale")]
|
||||
DiscreteScale,
|
||||
Enum
|
||||
}
|
||||
[EnumMember(Value = "discrete-scale")]
|
||||
DiscreteScale,
|
||||
Enum
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace YandexMusic.API.Models.Radio.Restriction
|
||||
namespace YandexMusic.API.Models.Radio.Restriction;
|
||||
|
||||
public class YRestrictionValue<T>
|
||||
{
|
||||
public class YRestrictionValue<T>
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public T Value { get; set; }
|
||||
}
|
||||
public string Name { get; set; }
|
||||
public T Value { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YAdParams
|
||||
{
|
||||
public class YAdParams
|
||||
{
|
||||
public decimal AdVolume { get; set; }
|
||||
public string CategoryId { get; set; }
|
||||
public int GenreId { get; set; }
|
||||
public string GenreName { get; set; }
|
||||
public string OtherParams { get; set; }
|
||||
public string PageRef { get; set; }
|
||||
public string PartnerId { get; set; }
|
||||
public string TargetRef { get; set; }
|
||||
}
|
||||
public decimal AdVolume { get; set; }
|
||||
public string CategoryId { get; set; }
|
||||
public int GenreId { get; set; }
|
||||
public string GenreName { get; set; }
|
||||
public string OtherParams { get; set; }
|
||||
public string PageRef { get; set; }
|
||||
public string PartnerId { get; set; }
|
||||
public string TargetRef { get; set; }
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YBrand
|
||||
{
|
||||
public class YBrand
|
||||
{
|
||||
public string AdvertiserUrl { get; set; }
|
||||
public string BackgroundColor { get; set; }
|
||||
public string BackgroundImageUri { get; set; }
|
||||
public string GlowColor { get; set; }
|
||||
public string MainImageUri { get; set; }
|
||||
public string Theme { get; set; }
|
||||
}
|
||||
public string AdvertiserUrl { get; set; }
|
||||
public string BackgroundColor { get; set; }
|
||||
public string BackgroundImageUri { get; set; }
|
||||
public string GlowColor { get; set; }
|
||||
public string MainImageUri { get; set; }
|
||||
public string Theme { get; set; }
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
using YandexMusic.API.Models.Track;
|
||||
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YSequenceItem
|
||||
{
|
||||
public class YSequenceItem
|
||||
{
|
||||
public bool Liked { get; set; }
|
||||
public YTrack Track { get; set; }
|
||||
public YTrackParameters TrackParameters { get; set; }
|
||||
public string Type { get; set; }
|
||||
}
|
||||
public bool Liked { get; set; }
|
||||
public YTrack Track { get; set; }
|
||||
public YTrackParameters TrackParameters { get; set; }
|
||||
public string Type { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
using YandexMusic.API.Models.Common;
|
||||
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YStation : YBaseModel
|
||||
{
|
||||
public class YStation : YBaseModel
|
||||
{
|
||||
public YAdParams AdParams { get; set; }
|
||||
public string CustomName { get; set; }
|
||||
public YStationData Data { get; set; }
|
||||
public string Explanation { get; set; }
|
||||
public List<YPrerolls> Prerolls { get; set; }
|
||||
public string RupTitle { get; set; }
|
||||
public string RupDescription { get; set; }
|
||||
public YStationSettings Settings { get; set; }
|
||||
public YStationSettings2 Settings2 { get; set; }
|
||||
public YStationDescription Station { get; set; }
|
||||
}
|
||||
public YAdParams AdParams { get; set; }
|
||||
public string CustomName { get; set; }
|
||||
public YStationData Data { get; set; }
|
||||
public string Explanation { get; set; }
|
||||
public List<YPrerolls> Prerolls { get; set; }
|
||||
public string RupTitle { get; set; }
|
||||
public string RupDescription { get; set; }
|
||||
public YStationSettings Settings { get; set; }
|
||||
public YStationSettings2 Settings2 { get; set; }
|
||||
public YStationDescription Station { get; set; }
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
using YandexMusic.API.Models.Artist;
|
||||
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YStationData
|
||||
{
|
||||
public class YStationData
|
||||
{
|
||||
public List<YArtist> Artists { get; set; }
|
||||
public YBrand Brand { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string ImageUri { get; set; }
|
||||
public string Title { get; set; }
|
||||
}
|
||||
public List<YArtist> Artists { get; set; }
|
||||
public YBrand Brand { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string ImageUri { get; set; }
|
||||
public string Title { get; set; }
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YStationDescription
|
||||
{
|
||||
public class YStationDescription
|
||||
{
|
||||
public string FullImageUrl { get; set; }
|
||||
public YStationIcon GeocellIcon { get; set; }
|
||||
public YStationIcon Icon { get; set; }
|
||||
public YStationId Id { get; set; }
|
||||
public string IdForFrom { get; set; }
|
||||
public string MtsFullImageUrl { get; set; }
|
||||
public YStationIcon MtsIcon { get; set; }
|
||||
public string Name { get; set; }
|
||||
public YStationId ParentId { get; set; }
|
||||
public YStationRestrictions Restrictions { get; set; }
|
||||
public YStationRestrictions2 Restrictions2 { get; set; }
|
||||
}
|
||||
public string FullImageUrl { get; set; }
|
||||
public YStationIcon GeocellIcon { get; set; }
|
||||
public YStationIcon Icon { get; set; }
|
||||
public YStationId Id { get; set; }
|
||||
public string IdForFrom { get; set; }
|
||||
public string MtsFullImageUrl { get; set; }
|
||||
public YStationIcon MtsIcon { get; set; }
|
||||
public string Name { get; set; }
|
||||
public YStationId ParentId { get; set; }
|
||||
public YStationRestrictions Restrictions { get; set; }
|
||||
public YStationRestrictions2 Restrictions2 { get; set; }
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
internal sealed class YStationFeedback
|
||||
{
|
||||
internal sealed class YStationFeedback
|
||||
{
|
||||
public YStationFeedbackType Type { get; set; }
|
||||
public long Timestamp { get; set; }
|
||||
public string From { get; set; }
|
||||
public double TotalPlayedSeconds { get; set; }
|
||||
public string TrackId { get; set; }
|
||||
}
|
||||
public YStationFeedbackType Type { get; set; }
|
||||
public long Timestamp { get; set; }
|
||||
public string From { get; set; }
|
||||
public double TotalPlayedSeconds { get; set; }
|
||||
public string TrackId { get; set; }
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public enum YStationFeedbackType
|
||||
{
|
||||
public enum YStationFeedbackType
|
||||
{
|
||||
RadioStarted,
|
||||
TrackStarted,
|
||||
TrackFinished,
|
||||
Skip
|
||||
}
|
||||
RadioStarted,
|
||||
TrackStarted,
|
||||
TrackFinished,
|
||||
Skip,
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YStationIcon
|
||||
{
|
||||
public class YStationIcon
|
||||
{
|
||||
public string BackgroundColor { get; set; }
|
||||
public string ImageUrl { get; set; }
|
||||
}
|
||||
public string BackgroundColor { get; set; }
|
||||
public string ImageUrl { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YStationId
|
||||
{
|
||||
public class YStationId
|
||||
{
|
||||
public string Tag { get; set; }
|
||||
public string Type { get; set; }
|
||||
}
|
||||
public string Tag { get; set; }
|
||||
public string Type { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using YandexMusic.API.Models.Radio.Restriction;
|
||||
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YStationRestrictions
|
||||
{
|
||||
public class YStationRestrictions
|
||||
{
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction Diversity { get; set; }
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction Energy { get; set; }
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction Language { get; set; }
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction Mood { get; set; }
|
||||
}
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction Diversity { get; set; }
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction Energy { get; set; }
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction Language { get; set; }
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction Mood { get; set; }
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using YandexMusic.API.Models.Radio.Restriction;
|
||||
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YStationRestrictions2
|
||||
{
|
||||
public class YStationRestrictions2
|
||||
{
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction Diversity { get; set; }
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction Language { get; set; }
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction MoodEnergy { get; set; }
|
||||
}
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction Diversity { get; set; }
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction Language { get; set; }
|
||||
[JsonConverter(typeof(YRestrictionConverter))]
|
||||
public YRestriction MoodEnergy { get; set; }
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YStationSequence
|
||||
{
|
||||
public class YStationSequence
|
||||
{
|
||||
public string BatchId { get; set; }
|
||||
public YStationId Id { get; set; }
|
||||
public bool Pumpkin { get; set; }
|
||||
public string RadioSessionId { get; set; }
|
||||
public List<YSequenceItem> Sequence { get; set; }
|
||||
}
|
||||
public string BatchId { get; set; }
|
||||
public YStationId Id { get; set; }
|
||||
public bool Pumpkin { get; set; }
|
||||
public string RadioSessionId { get; set; }
|
||||
public List<YSequenceItem> Sequence { get; set; }
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YStationSettings
|
||||
{
|
||||
public class YStationSettings
|
||||
{
|
||||
public string Diversity { get; set; }
|
||||
public string Energy { get; set; }
|
||||
public string Language { get; set; }
|
||||
public string Mood { get; set; }
|
||||
}
|
||||
public string Diversity { get; set; }
|
||||
public string Energy { get; set; }
|
||||
public string Language { get; set; }
|
||||
public string Mood { get; set; }
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YStationSettings2
|
||||
{
|
||||
public class YStationSettings2
|
||||
{
|
||||
public string Diversity { get; set; }
|
||||
public string Language { get; set; }
|
||||
public string MoodEnergy { get; set; }
|
||||
}
|
||||
public string Diversity { get; set; }
|
||||
public string Language { get; set; }
|
||||
public string MoodEnergy { get; set; }
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YStationsDashboard
|
||||
{
|
||||
public class YStationsDashboard
|
||||
{
|
||||
public string DashboardId { get; set; }
|
||||
public bool Pumpkin { get; set; }
|
||||
public List<YStation> Stations { get; set; }
|
||||
}
|
||||
public string DashboardId { get; set; }
|
||||
public bool Pumpkin { get; set; }
|
||||
public List<YStation> Stations { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
namespace YandexMusic.API.Models.Radio
|
||||
namespace YandexMusic.API.Models.Radio;
|
||||
|
||||
public class YTrackParameters
|
||||
{
|
||||
public class YTrackParameters
|
||||
{
|
||||
public int Bpm { get; set; }
|
||||
public int Hue { get; set; }
|
||||
public decimal Energy { get; set; }
|
||||
}
|
||||
public int Bpm { get; set; }
|
||||
public int Hue { get; set; }
|
||||
public decimal Energy { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user