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

34 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Specialized;
using System.Net;
using YandexMusic.API.Models.Common;
using YandexMusic.API.Requests.Common;
namespace YandexMusic.API.Requests.Track;
/// <summary>Особый запрос не к api.music.yandex.net, а к произвольному URL.</summary>
public class YStorageDownloadFileBuilder : YJsonRequestBuilder<YStorageDownloadFile?, string>
{
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)
=> new() { { "src", src.Split('?')[0] } };
protected override NameValueCollection GetQueryParams(string src)
{
var query = new NameValueCollection { { "format", "json" } };
var parts = src.Split('?');
if (parts.Length > 1)
{
foreach (var param in parts[1].Split('&'))
{
var kv = param.Split('=');
if (kv.Length == 2) query.Add(kv[0], kv[1]);
}
}
return query;
}
}