Полностью переписанное 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,24 +1,13 @@
|
||||
using System.Net;
|
||||
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Common;
|
||||
using YandexMusic.API.Models.Track;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
using YandexMusic.API.Requests.Common.Attributes;
|
||||
|
||||
namespace YandexMusic.API.Requests.Track;
|
||||
|
||||
[YApiRequest(WebRequestMethods.Http.Get, "tracks/{trackId}/similar")]
|
||||
public class YGetTrackSimilarBuilder : YRequestBuilder<YResponse<YTrackSimilar>, string>
|
||||
public class YGetTrackSimilarBuilder : YMusicRequestBuilder<YTrackSimilar?, string>
|
||||
{
|
||||
public YGetTrackSimilarBuilder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
|
||||
{
|
||||
}
|
||||
|
||||
public YGetTrackSimilarBuilder(YandexMusicApi api) : base(api) { }
|
||||
protected override string Method => WebRequestMethods.Http.Get;
|
||||
protected override string PathTemplate => "tracks/{trackId}/similar";
|
||||
protected override Dictionary<string, string> GetSubstitutions(string trackId)
|
||||
{
|
||||
return new Dictionary<string, string> {
|
||||
{ "trackId", trackId }
|
||||
};
|
||||
}
|
||||
=> new() { { "trackId", trackId } };
|
||||
}
|
||||
@@ -1,24 +1,13 @@
|
||||
using System.Net;
|
||||
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Common;
|
||||
using YandexMusic.API.Models.Track;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
using YandexMusic.API.Requests.Common.Attributes;
|
||||
|
||||
namespace YandexMusic.API.Requests.Track;
|
||||
|
||||
[YApiRequest(WebRequestMethods.Http.Get, "tracks/{trackId}/supplement")]
|
||||
public class YGetTrackSupplementBuilder : YRequestBuilder<YResponse<YTrackSupplement>, string>
|
||||
public class YGetTrackSupplementBuilder : YMusicRequestBuilder<YTrackSupplement?, string>
|
||||
{
|
||||
public YGetTrackSupplementBuilder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
|
||||
{
|
||||
}
|
||||
|
||||
public YGetTrackSupplementBuilder(YandexMusicApi api) : base(api) { }
|
||||
protected override string Method => WebRequestMethods.Http.Get;
|
||||
protected override string PathTemplate => "tracks/{trackId}/supplement";
|
||||
protected override Dictionary<string, string> GetSubstitutions(string trackId)
|
||||
{
|
||||
return new Dictionary<string, string> {
|
||||
{ "trackId", trackId }
|
||||
};
|
||||
}
|
||||
=> new() { { "trackId", trackId } };
|
||||
}
|
||||
@@ -1,25 +1,13 @@
|
||||
using System.Net;
|
||||
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Common;
|
||||
using YandexMusic.API.Models.Track;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
using YandexMusic.API.Requests.Common.Attributes;
|
||||
|
||||
namespace YandexMusic.API.Requests.Track;
|
||||
|
||||
[YApiRequest(WebRequestMethods.Http.Post, "tracks")]
|
||||
public class YGetTracksBuilder : YRequestBuilder<YResponse<List<YTrack>>, IEnumerable<string>>
|
||||
public class YGetTracksBuilder : YMusicRequestBuilder<List<YTrack>?, IEnumerable<string>>
|
||||
{
|
||||
public YGetTracksBuilder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
|
||||
{
|
||||
}
|
||||
|
||||
protected override HttpContent GetContent(IEnumerable<string> trackIds)
|
||||
{
|
||||
return new FormUrlEncodedContent(new Dictionary<string, string> {
|
||||
{ "track-ids", string.Join(",", trackIds) },
|
||||
{ "with-positions", "true" }
|
||||
});
|
||||
}
|
||||
public YGetTracksBuilder(YandexMusicApi api) : base(api) { }
|
||||
protected override string Method => WebRequestMethods.Http.Post;
|
||||
protected override string PathTemplate => "tracks";
|
||||
protected override HttpContent? GetContent(IEnumerable<string> trackIds)
|
||||
=> new FormUrlEncodedContent(new Dictionary<string, string> { { "track-ids", string.Join(",", trackIds) }, { "with-positions", "true" } });
|
||||
}
|
||||
@@ -1,37 +1,31 @@
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Track;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
using YandexMusic.API.Requests.Common.Attributes;
|
||||
|
||||
namespace YandexMusic.API.Requests.Track;
|
||||
|
||||
[YApiRequest(WebRequestMethods.Http.Post, "play-audio")]
|
||||
public class YSendTrackInfoBuilder : YRequestBuilder<string, (YTrack track, string from, bool fromCache, string playId, string playlistId, double totalPlayedSeconds, double endPositionSeconds)>
|
||||
public class YSendTrackInfoBuilder : YMusicRequestBuilder<string?, (YTrack track, string from, bool fromCache, string playId, string playlistId, double totalPlayedSeconds, double endPositionSeconds)>
|
||||
{
|
||||
public YSendTrackInfoBuilder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
protected override HttpContent GetContent((YTrack track, string from, bool fromCache, string playId, string playlistId, double totalPlayedSeconds, double endPositionSeconds) tuple)
|
||||
{
|
||||
Dictionary<string, string> formData = new() {
|
||||
var form = new Dictionary<string, string>
|
||||
{
|
||||
{ "track_id", tuple.track.Id },
|
||||
{ "from-cache", tuple.fromCache.ToString() },
|
||||
{ "play_id", tuple.playId },
|
||||
{ "uid", storage.User.Uid },
|
||||
{ "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 },
|
||||
{ "album-id", tuple.track.Albums?.FirstOrDefault()?.Id ?? "" },
|
||||
{ "from", tuple.from },
|
||||
{ "playlist-id", tuple.playlistId },
|
||||
{ "track-length-seconds", ((double)(tuple.track.DurationMs / 1000)).ToString(CultureInfo.InvariantCulture) },
|
||||
{ "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) },
|
||||
{ "end-position-seconds", tuple.endPositionSeconds.ToString(CultureInfo.InvariantCulture) }
|
||||
};
|
||||
|
||||
return new FormUrlEncodedContent(formData);
|
||||
return new FormUrlEncodedContent(form);
|
||||
}
|
||||
}
|
||||
@@ -1,42 +1,34 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Net;
|
||||
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Common;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
using YandexMusic.API.Requests.Common.Attributes;
|
||||
|
||||
namespace YandexMusic.API.Requests.Track;
|
||||
|
||||
[YRequest(WebRequestMethods.Http.Get, "{src}")]
|
||||
public class YStorageDownloadFileBuilder : YRequestBuilder<YStorageDownloadFile, string>
|
||||
/// <summary>Особый запрос – не к api.music.yandex.net, а к произвольному URL.</summary>
|
||||
public class YStorageDownloadFileBuilder : YJsonRequestBuilder<YStorageDownloadFile?, string>
|
||||
{
|
||||
public YStorageDownloadFileBuilder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
|
||||
{
|
||||
}
|
||||
public YStorageDownloadFileBuilder(YandexMusicApi api) : base(api) { }
|
||||
protected override string BaseUrl => ""; // не используется, т.к. URL берётся из параметра
|
||||
|
||||
protected override string Method => WebRequestMethods.Http.Get;
|
||||
|
||||
protected override string PathTemplate => "{src}";
|
||||
|
||||
protected override Dictionary<string, string> GetSubstitutions(string src)
|
||||
{
|
||||
return new Dictionary<string, string> {
|
||||
{ "src", src.Split('?')[0] }
|
||||
};
|
||||
}
|
||||
|
||||
=> new() { { "src", src.Split('?')[0] } };
|
||||
protected override NameValueCollection GetQueryParams(string src)
|
||||
{
|
||||
NameValueCollection query = new() {
|
||||
{ "format", "json" }
|
||||
};
|
||||
|
||||
src.Split('?')[1]
|
||||
.Split('&')
|
||||
.ToList()
|
||||
.ForEach(p =>
|
||||
var query = new NameValueCollection { { "format", "json" } };
|
||||
var parts = src.Split('?');
|
||||
if (parts.Length > 1)
|
||||
{
|
||||
foreach (var param in parts[1].Split('&'))
|
||||
{
|
||||
string[] param = p.Split('=');
|
||||
query.Add(param[0], param[1]);
|
||||
});
|
||||
|
||||
var kv = param.Split('=');
|
||||
if (kv.Length == 2) query.Add(kv[0], kv[1]);
|
||||
}
|
||||
}
|
||||
return query;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,16 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Net;
|
||||
|
||||
using YandexMusic.API.Common;
|
||||
using YandexMusic.API.Models.Common;
|
||||
using YandexMusic.API.Requests.Common;
|
||||
using YandexMusic.API.Requests.Common.Attributes;
|
||||
|
||||
namespace YandexMusic.API.Requests.Track;
|
||||
|
||||
[YApiRequest(WebRequestMethods.Http.Get, "tracks/{trackKey}/download-info")]
|
||||
public class YTrackDownloadInfoBuilder : YRequestBuilder<YResponse<List<YTrackDownloadInfo>>, (string trackKey, bool direct)>
|
||||
public class YTrackDownloadInfoBuilder : YMusicRequestBuilder<List<YTrackDownloadInfo>?, (string trackKey, bool direct)>
|
||||
{
|
||||
public YTrackDownloadInfoBuilder(YandexMusicApi yandex, AuthStorage auth) : base(yandex, auth)
|
||||
{
|
||||
}
|
||||
|
||||
public YTrackDownloadInfoBuilder(YandexMusicApi api) : base(api) { }
|
||||
protected override string Method => WebRequestMethods.Http.Get;
|
||||
protected override string PathTemplate => "tracks/{trackKey}/download-info";
|
||||
protected override Dictionary<string, string> GetSubstitutions((string trackKey, bool direct) tuple)
|
||||
{
|
||||
return new Dictionary<string, string> {
|
||||
{ "trackKey", tuple.trackKey }
|
||||
};
|
||||
}
|
||||
|
||||
=> new() { { "trackKey", tuple.trackKey } };
|
||||
protected override NameValueCollection GetQueryParams((string trackKey, bool direct) tuple)
|
||||
{
|
||||
return new NameValueCollection {
|
||||
{ "direct", tuple.direct.ToString() }
|
||||
};
|
||||
}
|
||||
=> new() { { "direct", tuple.direct.ToString() } };
|
||||
}
|
||||
Reference in New Issue
Block a user