using System.Text.Json; using DotBased.Monads; namespace Manager.YouTube.Parsers.Json; /// /// Parsing functionality for the response from endpoint: /youtubei/v1/account/account_menu /// public static class JsonAccountParser { public static Result 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); } } }