43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
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);
|
|
}
|
|
}
|
|
} |