[CHANGE] Get all account info
This commit is contained in:
@@ -5,4 +5,6 @@ public class AccountMenuInfo
|
||||
public string? AccountId { get; set; }
|
||||
public string? AccountHandle { get; set; }
|
||||
public string? ImageUrl { get; set; }
|
||||
public int ImageWidth { get; set; }
|
||||
public int ImageHeight { get; set; }
|
||||
}
|
@@ -128,16 +128,52 @@ public static class NetworkService
|
||||
return ResultError.Fail("Unable to get http client!");
|
||||
}
|
||||
|
||||
var response = await http.SendAsync(httpRequest);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
try
|
||||
{
|
||||
var responseResult = await response.Content.ReadAsStringAsync();
|
||||
return ResultError.Fail(responseResult);
|
||||
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 jsonDocument = JsonDocument.Parse(json);
|
||||
var activeAccountHeader = jsonDocument.RootElement
|
||||
.GetProperty("actions")[0]
|
||||
.GetProperty("openPopupAction")
|
||||
.GetProperty("popup")
|
||||
.GetProperty("multiPageMenuRenderer")
|
||||
.GetProperty("header")
|
||||
.GetProperty("activeAccountHeaderRenderer");
|
||||
|
||||
var matRuns = activeAccountHeader
|
||||
.GetProperty("manageAccountTitle")
|
||||
.GetProperty("runs");
|
||||
|
||||
var accountPhotos = activeAccountHeader
|
||||
.GetProperty("accountPhoto")
|
||||
.GetProperty("thumbnails");
|
||||
|
||||
var accInfo = new AccountMenuInfo();
|
||||
|
||||
var highestImage = accountPhotos.EnumerateArray().OrderBy(x => x.GetProperty("width").Deserialize<int>())
|
||||
.FirstOrDefault();
|
||||
accInfo.ImageUrl = highestImage.GetProperty("url").Deserialize<string>();
|
||||
accInfo.ImageWidth = highestImage.GetProperty("width").Deserialize<int>();
|
||||
accInfo.ImageHeight = highestImage.GetProperty("height").Deserialize<int>();
|
||||
|
||||
foreach (var run in matRuns.EnumerateArray())
|
||||
{
|
||||
var browseEndpoint = run.GetProperty("navigationEndpoint").GetProperty("browseEndpoint");
|
||||
accInfo.AccountId = browseEndpoint.GetProperty("browseId").GetString();
|
||||
accInfo.AccountHandle = browseEndpoint.GetProperty("canonicalBaseUrl").GetString()?.Replace("/", "");
|
||||
}
|
||||
return accInfo;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ResultError.Error(e);
|
||||
}
|
||||
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
var jsonObject = JsonNode.Parse(json);
|
||||
|
||||
return ResultError.Fail("Not implemented");
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using DotBased.Monads;
|
||||
using Manager.YouTube.Models.Innertube;
|
||||
|
||||
namespace Manager.YouTube;
|
||||
@@ -7,8 +8,10 @@ public sealed class YouTubeClient : IDisposable
|
||||
{
|
||||
public string Id { get; private set; } = "";
|
||||
public string AccountName => ClientState?.UserAccountName ?? "";
|
||||
public string? AccountHandle { get; set; }
|
||||
public string? AccountImage { get; set; }
|
||||
public string? UserAgent { get; set; }
|
||||
public CookieContainer CookieContainer { get; } = new() { Capacity = 100, PerDomainCapacity = 50 };
|
||||
public CookieContainer CookieContainer { get; } = new() { PerDomainCapacity = 50 };
|
||||
public ClientState? ClientState { get; private set; }
|
||||
public List<string> DatasyncIds { get; set; } = [];
|
||||
public Cookie? SapisidCookie => CookieContainer.GetAllCookies()["SAPISID"];
|
||||
@@ -35,14 +38,14 @@ public sealed class YouTubeClient : IDisposable
|
||||
_httpClient.DefaultRequestHeaders.Clear();
|
||||
}
|
||||
|
||||
public async Task BuildClientAsync()
|
||||
public async Task<Result> BuildClientAsync()
|
||||
{
|
||||
if (ClientState == null || !ClientState.LoggedIn)
|
||||
{
|
||||
var state = await NetworkService.GetClientStateAsync(this);
|
||||
if (!state.IsSuccess)
|
||||
{
|
||||
return;
|
||||
return state;
|
||||
}
|
||||
ClientState = state.Value;
|
||||
}
|
||||
@@ -52,7 +55,7 @@ public sealed class YouTubeClient : IDisposable
|
||||
var datasyncResult = await NetworkService.GetDatasyncIds(this);
|
||||
if (!datasyncResult.IsSuccess)
|
||||
{
|
||||
return;
|
||||
return datasyncResult;
|
||||
}
|
||||
|
||||
foreach (var id in datasyncResult.Value)
|
||||
@@ -63,7 +66,17 @@ public sealed class YouTubeClient : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
var accountInfo = await NetworkService.GetCurrentAccountInfoAsync(this);
|
||||
var accountInfoResult = await NetworkService.GetCurrentAccountInfoAsync(this);
|
||||
if (!accountInfoResult.IsSuccess)
|
||||
{
|
||||
return accountInfoResult;
|
||||
}
|
||||
|
||||
Id = accountInfoResult.Value.AccountId ?? "";
|
||||
AccountHandle = accountInfoResult.Value.AccountHandle;
|
||||
AccountImage = accountInfoResult.Value.ImageUrl;
|
||||
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
Reference in New Issue
Block a user