[CHANGE] Cookie login fixed
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using System.Net;
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using DotBased.Monads;
|
||||
using Manager.YouTube.Models;
|
||||
using Manager.YouTube.Models.Innertube;
|
||||
using Manager.YouTube.Parsers;
|
||||
using Manager.YouTube.Util;
|
||||
@@ -20,12 +22,8 @@ public static class NetworkService
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(Origin)
|
||||
};
|
||||
httpRequest.Headers.IfModifiedSince = new DateTimeOffset(DateTime.UtcNow);
|
||||
httpRequest.Headers.Clear();
|
||||
httpRequest.Headers.UserAgent.ParseAdd(client.UserAgent);
|
||||
httpRequest.Headers.Accept.ParseAdd("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
||||
httpRequest.Headers.Connection.Add("keep-alive");
|
||||
httpRequest.Headers.Add("DNT", "1");
|
||||
httpRequest.Headers.Add("Upgrade-Insecure-Requests", "1");
|
||||
|
||||
var http = client.GetHttpClient();
|
||||
if (http == null)
|
||||
@@ -59,7 +57,48 @@ public static class NetworkService
|
||||
return clientState == null ? ResultError.Fail("Unable to parse client state!") : clientState;
|
||||
}
|
||||
|
||||
public static async Task<Result> GetCurrentAccountInfoAsync(YouTubeClient client)
|
||||
public static async Task<Result<string[]>> GetDatasyncIds(YouTubeClient client)
|
||||
{
|
||||
if (client.ClientState is not { LoggedIn: true } || client.CookieContainer.Count == 0)
|
||||
{
|
||||
return ResultError.Fail("Client is not logged in, requires logged in client for this endpoint (/getDatasyncIdsEndpoint).");
|
||||
}
|
||||
|
||||
var httpClient = client.GetHttpClient();
|
||||
if (httpClient == null)
|
||||
{
|
||||
return ResultError.Fail("Unable to get http client!");
|
||||
}
|
||||
|
||||
var httpRequest = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri($"{Origin}/getDatasyncIdsEndpoint")
|
||||
};
|
||||
httpRequest.Headers.UserAgent.ParseAdd(client.UserAgent);
|
||||
httpRequest.Headers.Add("Origin", Origin);
|
||||
|
||||
var response = await httpClient.SendAsync(httpRequest);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
var responseResult = await response.Content.ReadAsStringAsync();
|
||||
return ResultError.Fail(responseResult);
|
||||
}
|
||||
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
var datasyncIdsJson = JsonNode.Parse(responseContent.Replace(")]}'", ""));
|
||||
|
||||
var isLoggedOut = datasyncIdsJson?["responseContext"]?["mainAppWebResponseContext"]?["loggedOut"]
|
||||
.Deserialize<bool>() ?? true;
|
||||
if (!isLoggedOut)
|
||||
{
|
||||
return datasyncIdsJson?["datasyncIds"].Deserialize<string[]>() ?? [];
|
||||
}
|
||||
|
||||
return ResultError.Fail("Failed to get datasyncIds!");
|
||||
}
|
||||
|
||||
public static async Task<Result<AccountMenuInfo>> GetCurrentAccountInfoAsync(YouTubeClient client)
|
||||
{
|
||||
if (client.ClientState is not { LoggedIn: true })
|
||||
{
|
||||
|
Reference in New Issue
Block a user