[CHANGE] Split up json parsing, added getting account info

This commit is contained in:
max
2025-09-07 22:18:56 +02:00
parent 3db61b599d
commit b2c6003203
11 changed files with 198 additions and 48 deletions

View File

@@ -0,0 +1,43 @@
using System.Text.Json;
using DotBased.Monads;
namespace Manager.YouTube.Parsers.Json;
/// <summary>
/// Parsing functionality for the response from endpoint: /youtubei/v1/account/account_menu
/// </summary>
public static class JsonAccountParser
{
public static Result<string> ParseAccountId(string json)
{
try
{
var jsonDocument = JsonDocument.Parse(json);
var id = jsonDocument.RootElement
.GetProperty("actions")[0]
.GetProperty("openPopupAction")
.GetProperty("popup")
.GetProperty("multiPageMenuRenderer")
.GetProperty("header")
.GetProperty("activeAccountHeaderRenderer")
.GetProperty("manageAccountTitle")
.GetProperty("runs")
.EnumerateArray()
.FirstOrDefault()
.GetProperty("navigationEndpoint")
.GetProperty("browseEndpoint")
.GetProperty("browseId").GetString();
if (string.IsNullOrWhiteSpace(id))
{
return ResultError.Fail("Unable to get account id!");
}
return id;
}
catch (Exception e)
{
return ResultError.Error(e);
}
}
}