Files
YandexMusic/YandexMusic.API/Requests/Track/YSendTrackInfoBuilder.cs
FrigaT 36e28ce3fe
All checks were successful
Release / pack-and-publish (release) Successful in 36s
Полностью переписанное api
2026-04-19 17:00:05 +03:00

31 lines
1.7 KiB
C#

using System.Globalization;
using System.Net;
using YandexMusic.API.Models.Track;
namespace YandexMusic.API.Requests.Track;
public class YSendTrackInfoBuilder : YMusicRequestBuilder<string?, (YTrack track, string from, bool fromCache, string playId, string playlistId, double totalPlayedSeconds, double endPositionSeconds)>
{
public YSendTrackInfoBuilder(YandexMusicApi api) : base(api) { }
protected override string Method => WebRequestMethods.Http.Post;
protected override string PathTemplate => "play-audio";
protected override HttpContent? GetContent((YTrack track, string from, bool fromCache, string playId, string playlistId, double totalPlayedSeconds, double endPositionSeconds) tuple)
{
var form = new Dictionary<string, string>
{
{ "track_id", tuple.track.Id },
{ "from-cache", tuple.fromCache.ToString() },
{ "play_id", tuple.playId },
{ "uid", Api.Storage.User.Uid },
{ "timestamp", DateTime.Now.ToString("o", CultureInfo.InvariantCulture) },
{ "client-now", DateTime.Now.ToString("o", CultureInfo.InvariantCulture) },
{ "album-id", tuple.track.Albums?.FirstOrDefault()?.Id ?? "" },
{ "from", tuple.from },
{ "playlist-id", tuple.playlistId },
{ "track-length-seconds", (tuple.track.DurationMs / 1000.0).ToString(CultureInfo.InvariantCulture) },
{ "total-played-seconds", tuple.totalPlayedSeconds.ToString(CultureInfo.InvariantCulture) },
{ "end-position-seconds", tuple.endPositionSeconds.ToString(CultureInfo.InvariantCulture) }
};
return new FormUrlEncodedContent(form);
}
}