[CHANGE] Split up json parsing, added getting account info
This commit is contained in:
43
Manager.YouTube/Parsers/Json/JsonAccountParser.cs
Normal file
43
Manager.YouTube/Parsers/Json/JsonAccountParser.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user