31 lines
1.7 KiB
C#
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);
|
|
}
|
|
} |