[CHANGE] Cookie login fixed
This commit is contained in:
@@ -8,9 +8,10 @@ public sealed class YouTubeClient : IDisposable
|
||||
public string Id { get; private set; } = "";
|
||||
public string AccountName => ClientState?.UserAccountName ?? "";
|
||||
public string? UserAgent { get; set; }
|
||||
public CookieContainer CookieContainer { get; } = new();
|
||||
public CookieContainer CookieContainer { get; } = new() { Capacity = 100, PerDomainCapacity = 50 };
|
||||
public ClientState? ClientState { get; private set; }
|
||||
public Cookie? SapisidCookie => CookieContainer.GetAllCookies()["SAPISID"] ?? CookieContainer.GetAllCookies()["__Secure-3PAPISID"];
|
||||
public List<string> DatasyncIds { get; set; } = [];
|
||||
public Cookie? SapisidCookie => CookieContainer.GetAllCookies()["SAPISID"];
|
||||
public HttpClient? GetHttpClient() => _httpClient;
|
||||
|
||||
private HttpClient? _httpClient;
|
||||
@@ -31,9 +32,10 @@ public sealed class YouTubeClient : IDisposable
|
||||
CookieContainer = CookieContainer
|
||||
};
|
||||
_httpClient = new HttpClient(clientHandler);
|
||||
_httpClient.DefaultRequestHeaders.Clear();
|
||||
}
|
||||
|
||||
public async Task GetStateAsync()
|
||||
public async Task BuildClientAsync()
|
||||
{
|
||||
if (ClientState == null || !ClientState.LoggedIn)
|
||||
{
|
||||
@@ -44,7 +46,23 @@ public sealed class YouTubeClient : IDisposable
|
||||
}
|
||||
ClientState = state.Value;
|
||||
}
|
||||
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ClientState.WebPlayerContextConfig?.WebPlayerContext?.DatasyncId))
|
||||
{
|
||||
var datasyncResult = await NetworkService.GetDatasyncIds(this);
|
||||
if (!datasyncResult.IsSuccess)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var id in datasyncResult.Value)
|
||||
{
|
||||
if (DatasyncIds.Contains(id))
|
||||
continue;
|
||||
DatasyncIds.Add(id);
|
||||
}
|
||||
}
|
||||
|
||||
var accountInfo = await NetworkService.GetCurrentAccountInfoAsync(this);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user