Полностью переписанное 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,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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user