Полностью переписанное api
All checks were successful
Release / pack-and-publish (release) Successful in 36s
All checks were successful
Release / pack-and-publish (release) Successful in 36s
This commit is contained in:
@@ -1,25 +1,13 @@
|
||||
using System.Net;
|
||||
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Common;
|
||||
using YandexMusic.API.Models.Radio;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
using YandexMusic.API.Requests.Common.Attributes;
|
||||
|
||||
namespace YandexMusic.API.Requests.Radio;
|
||||
|
||||
[YApiRequest(WebRequestMethods.Http.Get, "rotor/station/{type}:{tag}/info")]
|
||||
public class YGetStationBuilder : YRequestBuilder<YResponse<List<YStation>>, (string type, string tag)>
|
||||
public class YGetStationBuilder : YMusicRequestBuilder<List<YStation>?, (string type, string tag)>
|
||||
{
|
||||
public YGetStationBuilder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
|
||||
{
|
||||
}
|
||||
|
||||
public YGetStationBuilder(YandexMusicApi api) : base(api) { }
|
||||
protected override string Method => WebRequestMethods.Http.Get;
|
||||
protected override string PathTemplate => "rotor/station/{type}:{tag}/info";
|
||||
protected override Dictionary<string, string> GetSubstitutions((string type, string tag) tuple)
|
||||
{
|
||||
return new Dictionary<string, string> {
|
||||
{ "type", tuple.type },
|
||||
{ "tag", tuple.tag }
|
||||
};
|
||||
}
|
||||
=> new() { { "type", tuple.type }, { "tag", tuple.tag } };
|
||||
}
|
||||
@@ -1,38 +1,21 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Net;
|
||||
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Common;
|
||||
using YandexMusic.API.Models.Radio;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
using YandexMusic.API.Requests.Common.Attributes;
|
||||
|
||||
namespace YandexMusic.API.Requests.Radio;
|
||||
|
||||
[YApiRequest(WebRequestMethods.Http.Get, "rotor/station/{type}:{tag}/tracks")]
|
||||
public class YGetStationTracksBuilder : YRequestBuilder<YResponse<YStationSequence>, (YStationDescription station, string prevTrackId)>
|
||||
public class YGetStationTracksBuilder : YMusicRequestBuilder<YStationSequence?, (YStationDescription station, string prevTrackId)>
|
||||
{
|
||||
public YGetStationTracksBuilder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
|
||||
{
|
||||
}
|
||||
|
||||
public YGetStationTracksBuilder(YandexMusicApi api) : base(api) { }
|
||||
protected override string Method => WebRequestMethods.Http.Get;
|
||||
protected override string PathTemplate => "rotor/station/{type}:{tag}/tracks";
|
||||
protected override Dictionary<string, string> GetSubstitutions((YStationDescription station, string prevTrackId) tuple)
|
||||
{
|
||||
return new Dictionary<string, string> {
|
||||
{ "type", tuple.station.Id.Type },
|
||||
{ "tag", tuple.station.Id.Tag },
|
||||
};
|
||||
}
|
||||
|
||||
=> new() { { "type", tuple.station.Id.Type }, { "tag", tuple.station.Id.Tag } };
|
||||
protected override NameValueCollection GetQueryParams((YStationDescription station, string prevTrackId) tuple)
|
||||
{
|
||||
NameValueCollection query = new() {
|
||||
{ "settings2", "true" }
|
||||
};
|
||||
|
||||
var query = new NameValueCollection { { "settings2", "true" } };
|
||||
if (!string.IsNullOrEmpty(tuple.prevTrackId))
|
||||
query.Add("queue", tuple.prevTrackId);
|
||||
|
||||
return base.GetQueryParams(tuple);
|
||||
return query;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,12 @@
|
||||
using System.Net;
|
||||
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Common;
|
||||
using YandexMusic.API.Models.Radio;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
using YandexMusic.API.Requests.Common.Attributes;
|
||||
|
||||
namespace YandexMusic.API.Requests.Radio;
|
||||
|
||||
[YApiRequest(WebRequestMethods.Http.Get, "rotor/stations/list")]
|
||||
public class YGetStationsBuilder : YRequestBuilder<YResponse<List<YStation>>, object>
|
||||
public class YGetStationsBuilder : YMusicRequestBuilder<List<YStation>?, object>
|
||||
{
|
||||
public YGetStationsBuilder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
|
||||
{
|
||||
}
|
||||
public YGetStationsBuilder(YandexMusicApi api) : base(api) { }
|
||||
protected override string Method => WebRequestMethods.Http.Get;
|
||||
protected override string PathTemplate => "rotor/stations/list";
|
||||
}
|
||||
@@ -1,17 +1,12 @@
|
||||
using System.Net;
|
||||
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Common;
|
||||
using YandexMusic.API.Models.Radio;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
using YandexMusic.API.Requests.Common.Attributes;
|
||||
|
||||
namespace YandexMusic.API.Requests.Radio;
|
||||
|
||||
[YApiRequest(WebRequestMethods.Http.Get, "rotor/stations/dashboard")]
|
||||
public class YGetStationsDashboardBuilder : YRequestBuilder<YResponse<YStationsDashboard>, object>
|
||||
public class YGetStationsDashboardBuilder : YMusicRequestBuilder<YStationsDashboard?, object>
|
||||
{
|
||||
public YGetStationsDashboardBuilder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
|
||||
{
|
||||
}
|
||||
public YGetStationsDashboardBuilder(YandexMusicApi api) : base(api) { }
|
||||
protected override string Method => WebRequestMethods.Http.Get;
|
||||
protected override string PathTemplate => "rotor/stations/dashboard";
|
||||
}
|
||||
@@ -4,42 +4,26 @@ using System.Net.Http.Json;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Common;
|
||||
using YandexMusic.API.Models.Radio;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
using YandexMusic.API.Requests.Common.Attributes;
|
||||
|
||||
namespace YandexMusic.API.Requests.Radio;
|
||||
|
||||
[YApiRequest(WebRequestMethods.Http.Post, "rotor/station/{type}:{tag}/settings2")]
|
||||
public class YSetSettings2Builder : YRequestBuilder<YResponse<string>, (YStationDescription station, YStationSettings2 settings2)>
|
||||
public class YSetSettings2Builder : YMusicRequestBuilder<string?, (YStationDescription station, YStationSettings2 settings2)>
|
||||
{
|
||||
public YSetSettings2Builder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
|
||||
{
|
||||
}
|
||||
|
||||
public YSetSettings2Builder(YandexMusicApi api) : base(api) { }
|
||||
protected override string Method => WebRequestMethods.Http.Post;
|
||||
protected override string PathTemplate => "rotor/station/{type}:{tag}/settings2";
|
||||
protected override Dictionary<string, string> GetSubstitutions((YStationDescription station, YStationSettings2 settings2) tuple)
|
||||
=> new() { { "type", tuple.station.Id.Type }, { "tag", tuple.station.Id.Tag } };
|
||||
protected override HttpContent? GetContent((YStationDescription station, YStationSettings2 settings2) tuple)
|
||||
{
|
||||
return new Dictionary<string, string> {
|
||||
{ "type", tuple.station.Id.Type },
|
||||
{ "tag", tuple.station.Id.Tag },
|
||||
};
|
||||
}
|
||||
|
||||
protected override HttpContent GetContent((YStationDescription station, YStationSettings2 settings2) tuple)
|
||||
{
|
||||
JsonSerializerOptions settings = new()
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
Converters = {
|
||||
new JsonStringEnumConverter()
|
||||
},
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
Converters = { new JsonStringEnumConverter() }
|
||||
};
|
||||
|
||||
return JsonContent.Create(tuple.settings2, new MediaTypeHeaderValue("application/json"), settings);
|
||||
return JsonContent.Create(tuple.settings2, new MediaTypeHeaderValue("application/json"), options);
|
||||
}
|
||||
}
|
||||
@@ -5,67 +5,45 @@ using System.Net.Http.Json;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Radio;
|
||||
using YandexMusic.API.Models.Track;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
using YandexMusic.API.Requests.Common.Attributes;
|
||||
|
||||
namespace YandexMusic.API.Requests.Radio;
|
||||
|
||||
[YApiRequest(WebRequestMethods.Http.Post, "rotor/station/{type}:{tag}/feedback")]
|
||||
public class YSetStationFeedbackBuilder : YRequestBuilder<string, (YStationFeedbackType type, YStation station, YTrack track, string batchId, double totalPlayedSeconds)>
|
||||
public class YSetStationFeedbackBuilder : YMusicRequestBuilder<string?, (YStationFeedbackType type, YStation station, YTrack? track, string batchId, double totalPlayedSeconds)>
|
||||
{
|
||||
public YSetStationFeedbackBuilder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
|
||||
public YSetStationFeedbackBuilder(YandexMusicApi api) : base(api) { }
|
||||
protected override string Method => WebRequestMethods.Http.Post;
|
||||
protected override string PathTemplate => "rotor/station/{type}:{tag}/feedback";
|
||||
protected override Dictionary<string, string> GetSubstitutions((YStationFeedbackType type, YStation station, YTrack? track, string batchId, double totalPlayedSeconds) tuple)
|
||||
=> new() { { "type", tuple.station.Station.Id.Type }, { "tag", tuple.station.Station.Id.Tag } };
|
||||
protected override NameValueCollection GetQueryParams((YStationFeedbackType type, YStation station, YTrack? track, string batchId, double totalPlayedSeconds) tuple)
|
||||
{
|
||||
var query = new NameValueCollection();
|
||||
if (!string.IsNullOrWhiteSpace(tuple.batchId))
|
||||
query.Add("batch-id", tuple.batchId);
|
||||
return query;
|
||||
}
|
||||
|
||||
protected override Dictionary<string, string> GetSubstitutions((YStationFeedbackType type, YStation station, YTrack track, string batchId, double totalPlayedSeconds) tuple)
|
||||
protected override HttpContent? GetContent((YStationFeedbackType type, YStation station, YTrack? track, string batchId, double totalPlayedSeconds) tuple)
|
||||
{
|
||||
return new Dictionary<string, string> {
|
||||
{ "type", tuple.station.Station.Id.Type },
|
||||
{ "tag", tuple.station.Station.Id.Tag }
|
||||
};
|
||||
}
|
||||
|
||||
protected override HttpContent GetContent((YStationFeedbackType type, YStation station, YTrack track, string batchId, double totalPlayedSeconds) tuple)
|
||||
{
|
||||
long timestamp = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
|
||||
|
||||
JsonSerializerOptions settings = new()
|
||||
{
|
||||
Converters = {
|
||||
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)
|
||||
},
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault
|
||||
};
|
||||
|
||||
YStationFeedback feedBack = new()
|
||||
var feedback = new YStationFeedback
|
||||
{
|
||||
Type = tuple.type,
|
||||
From = tuple.station.Station.IdForFrom,
|
||||
Timestamp = timestamp
|
||||
Timestamp = DateTimeOffset.Now.ToUnixTimeSeconds()
|
||||
};
|
||||
|
||||
if (tuple.track != null)
|
||||
feedBack.TrackId = tuple.track.Id;
|
||||
|
||||
feedback.TrackId = tuple.track.Id;
|
||||
if (tuple.totalPlayedSeconds > 0)
|
||||
feedBack.TotalPlayedSeconds = tuple.totalPlayedSeconds;
|
||||
feedback.TotalPlayedSeconds = tuple.totalPlayedSeconds;
|
||||
|
||||
return JsonContent.Create(feedBack, new MediaTypeHeaderValue("application/json"), settings); ;
|
||||
}
|
||||
|
||||
protected override NameValueCollection GetQueryParams((YStationFeedbackType type, YStation station, YTrack track, string batchId, double totalPlayedSeconds) tuple)
|
||||
{
|
||||
NameValueCollection query = new();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(tuple.batchId))
|
||||
query.Add("batch-id", tuple.batchId);
|
||||
|
||||
return query;
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
return JsonContent.Create(feedback, new MediaTypeHeaderValue("application/json"), options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user