[CHANGE] Get all account info
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
@inject ISnackbar SnackbarService
|
||||
|
||||
<ForcedLoadingOverlay Visible="_isLoading"/>
|
||||
|
||||
<MudDialog>
|
||||
@@ -14,11 +16,11 @@
|
||||
<MudButton Variant="Variant.Outlined" Disabled="@(string.IsNullOrWhiteSpace(_cookieDomain) || string.IsNullOrWhiteSpace(_cookieText))" OnClick="ApplyTextCookies">Apply</MudButton>
|
||||
}
|
||||
|
||||
<MudStack Row Spacing="2" AlignItems="AlignItems.Stretch" Justify="Justify.SpaceEvenly" StretchItems="StretchItems.All">
|
||||
<MudStack Spacing="2" Style="width: 100%">
|
||||
<MudStack Row Spacing="2" AlignItems="AlignItems.Start" Justify="Justify.SpaceEvenly" StretchItems="StretchItems.All">
|
||||
<MudStack Spacing="2">
|
||||
<MudTextField Label="UserAgent" Required @bind-Value="@Client.UserAgent"/>
|
||||
</MudStack>
|
||||
<MudSimpleTable Style="width: 100%" Bordered Dense Elevation="0" Outlined Square Hover>
|
||||
<MudSimpleTable Bordered Dense Elevation="0" Outlined Square Hover>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Account id:</td>
|
||||
@@ -28,6 +30,10 @@
|
||||
<td>Account name:</td>
|
||||
<td>@Client.AccountName</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Account handle:</td>
|
||||
<td>@Client.AccountHandle</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>User agent:</td>
|
||||
<td>@Client.UserAgent</td>
|
||||
@@ -51,6 +57,10 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</MudSimpleTable>
|
||||
@if (!string.IsNullOrWhiteSpace(Client.AccountImage))
|
||||
{
|
||||
<MudImage Src="@Client.AccountImage" Elevation="0" ObjectFit="ObjectFit.Contain"/>
|
||||
}
|
||||
</MudStack>
|
||||
|
||||
<MudDataGrid Items="Client.CookieContainer.GetAllCookies()" Dense Elevation="0" Outlined>
|
||||
@@ -84,14 +94,6 @@
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
<PropertyColumn Title="Expires" Property="x => x.Expires"/>
|
||||
|
||||
<TemplateColumn>
|
||||
<CellTemplate>
|
||||
<MudTooltip Text="Remove">
|
||||
<MudIconButton Size="Size.Small" Icon="@Icons.Material.Filled.Remove" Color="Color.Error" OnClick="@(() => RemoveCookie(context.Item))"/>
|
||||
</MudTooltip>
|
||||
</CellTemplate>
|
||||
</TemplateColumn>
|
||||
</Columns>
|
||||
</MudDataGrid>
|
||||
</MudStack>
|
||||
|
@@ -29,17 +29,6 @@ namespace Manager.App.Components.Dialogs
|
||||
Client.CookieContainer.Add(new Cookie { Name = "SET_NAME", Domain = ".youtube.com" });
|
||||
}
|
||||
|
||||
private async Task RemoveCookie(Cookie? cookie)
|
||||
{
|
||||
if (cookie == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cookie.Expired = true;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private void ToggleCookieTextImport()
|
||||
{
|
||||
_showCookieTextImport =! _showCookieTextImport;
|
||||
@@ -97,13 +86,27 @@ namespace Manager.App.Components.Dialogs
|
||||
|
||||
private bool CanSave()
|
||||
{
|
||||
return Client.ClientState is { LoggedIn: true };
|
||||
if (Client.ClientState == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Client.Id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Client.SapisidCookie != null && Client.ClientState.LoggedIn;
|
||||
}
|
||||
|
||||
private async Task ValidateAccount()
|
||||
{
|
||||
_isLoading = true;
|
||||
await Client.BuildClientAsync();
|
||||
var result = await Client.BuildClientAsync();
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
SnackbarService.Add(result.Error?.Description ?? "Error validating account.", Severity.Error);
|
||||
}
|
||||
_isLoading = false;
|
||||
}
|
||||
|
||||
|
@@ -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