39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using DotBased.Monads;
|
|
using Manager.YouTube.Util;
|
|
|
|
namespace Manager.YouTube;
|
|
|
|
public static class NetworkService
|
|
{
|
|
public const string Origin = "https://www.youtube.com";
|
|
|
|
public static async Task<Result<string>> MakeRequestAsync(HttpRequestMessage request, YouTubeClient client, bool skipAuthenticationHeader = false)
|
|
{
|
|
request.Headers.Add("Origin", Origin);
|
|
request.Headers.UserAgent.ParseAdd(client.UserAgent);
|
|
if (client.SapisidCookie != null && !skipAuthenticationHeader)
|
|
{
|
|
request.Headers.Authorization = AuthenticationUtilities.GetSapisidHashHeader(client.GetDatasyncId(), client.SapisidCookie.Value, Origin);
|
|
}
|
|
|
|
try
|
|
{
|
|
var response = await client.HttpClient.SendAsync(request);
|
|
var contentString = await response.Content.ReadAsStringAsync();
|
|
if (!response.IsSuccessStatusCode)
|
|
{
|
|
return ResultError.Fail(contentString);
|
|
}
|
|
return contentString;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
return ResultError.Error(e);
|
|
}
|
|
}
|
|
|
|
public static async Task<Result<byte[]>> DownloadBytesAsync(HttpRequestMessage request, YouTubeClient client)
|
|
{
|
|
return ResultError.Fail("Not implemented");
|
|
}
|
|
} |