[CHANGE] Working on auth hash
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using DotBased.Monads;
|
||||
using Manager.YouTube.Models.Innertube;
|
||||
using Manager.YouTube.Parsers;
|
||||
using Manager.YouTube.Util;
|
||||
|
||||
namespace Manager.YouTube;
|
||||
|
||||
public static class NetworkService
|
||||
{
|
||||
private const string Origin = "https://www.youtube.com/";
|
||||
private const string Origin = "https://www.youtube.com";
|
||||
|
||||
public static async Task<Result<ClientState>> GetClientStateAsync(YouTubeClient client)
|
||||
{
|
||||
@@ -33,7 +37,7 @@ public static class NetworkService
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var responseResult = await response.Content.ReadAsStringAsync();
|
||||
return Result<ClientState>.Fail(ResultError.Fail(responseResult));
|
||||
return ResultError.Fail(responseResult);
|
||||
}
|
||||
var responseHtml = await response.Content.ReadAsStringAsync();
|
||||
var clientStateResult = HtmlParser.GetStateJson(responseHtml);
|
||||
@@ -55,21 +59,46 @@ public static class NetworkService
|
||||
return clientState == null ? ResultError.Fail("Unable to parse client state!") : clientState;
|
||||
}
|
||||
|
||||
public static async Task<Result> GetCurrentAccountAsync()
|
||||
public static async Task<Result> GetCurrentAccountInfoAsync(YouTubeClient client)
|
||||
{
|
||||
//URL: /youtubei/v1/account/account_menu
|
||||
// Payload
|
||||
// "context": {
|
||||
// "client": {CLIENT INFO FROM STATE}
|
||||
// }
|
||||
if (client.ClientState is not { LoggedIn: true })
|
||||
{
|
||||
return ResultError.Fail("Client not logged in!");
|
||||
}
|
||||
|
||||
var httpRequest = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri($"{Origin}/youtubei/v1/account/account_menu")
|
||||
};
|
||||
httpRequest.Headers.UserAgent.ParseAdd(client.UserAgent);
|
||||
httpRequest.Headers.Add("Origin", Origin);
|
||||
|
||||
if (client.SapisidCookie != null)
|
||||
{
|
||||
httpRequest.Headers.Authorization = AuthenticationUtilities.GetSapisidHashHeader(client.ClientState.WebPlayerContextConfig?.WebPlayerContext?.DatasyncId ?? "", client.SapisidCookie.Value, Origin);
|
||||
}
|
||||
|
||||
var serializedContext = JsonSerializer.SerializeToNode(client.ClientState.InnerTubeContext);
|
||||
var contextJson = new JsonObject { { "context", serializedContext } };
|
||||
httpRequest.Content = new StringContent(contextJson.ToJsonString(), Encoding.UTF8, MediaTypeNames.Application.Json);
|
||||
|
||||
var http = client.GetHttpClient();
|
||||
if (http == null)
|
||||
{
|
||||
return ResultError.Fail("Unable to get http client!");
|
||||
}
|
||||
|
||||
var response = await http.SendAsync(httpRequest);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var responseResult = await response.Content.ReadAsStringAsync();
|
||||
return ResultError.Fail(responseResult);
|
||||
}
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
var jsonObject = JsonNode.Parse(json);
|
||||
|
||||
/* Auth header
|
||||
* if (client.SapisidCookie != null)
|
||||
{
|
||||
httpRequest.Headers.Authorization = AuthenticationUtilities.GetSapisidHashHeader(client.SapisidCookie.Value, origin);
|
||||
httpRequest.Headers.Add("Origin", origin);
|
||||
}
|
||||
*/
|
||||
return ResultError.Fail("Not implemented");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user