[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

@@ -5,6 +5,7 @@ using System.Text.Json.Nodes;
using DotBased.Monads;
using Manager.YouTube.Models.Innertube;
using Manager.YouTube.Parsers;
using Manager.YouTube.Parsers.Json;
using Manager.YouTube.Util;
namespace Manager.YouTube;
@@ -52,6 +53,8 @@ public static class NetworkService
return ResultError.Error(e, "Error while parsing JSON!");
}
client.External.Information.IsPremiumUser = clientStateResult.Value.Item2;
return clientState == null ? ResultError.Fail("Unable to parse client state!") : clientState;
}
@@ -125,7 +128,8 @@ public static class NetworkService
{
return ResultError.Fail("Unable to get http client!");
}
string json;
try
{
var response = await http.SendAsync(httpRequest);
@@ -135,31 +139,14 @@ public static class NetworkService
return ResultError.Fail(responseResult);
}
var json = await response.Content.ReadAsStringAsync();
var jsonDocument = JsonDocument.Parse(json);
var matRuns = jsonDocument.RootElement
.GetProperty("actions")[0]
.GetProperty("openPopupAction")
.GetProperty("popup")
.GetProperty("multiPageMenuRenderer")
.GetProperty("header")
.GetProperty("activeAccountHeaderRenderer")
.GetProperty("manageAccountTitle")
.GetProperty("runs");
var firstElement = matRuns.EnumerateArray().FirstOrDefault();
var id = firstElement.GetProperty("navigationEndpoint").GetProperty("browseEndpoint").GetProperty("browseId").GetString();
if (string.IsNullOrWhiteSpace(id))
{
return ResultError.Fail("Unable to get account id!");
}
return id;
json = await response.Content.ReadAsStringAsync();
}
catch (Exception e)
{
return ResultError.Error(e);
}
return JsonAccountParser.ParseAccountId(json);
}
public static async Task<Result<ChannelFetch>> GetChannelAsync(string channelId, YouTubeClient client)
@@ -204,8 +191,10 @@ public static class NetworkService
}
var jsonContent = await response.Content.ReadAsStringAsync();
var parsed = ChannelJsonParser.ParseJsonToChannelData(jsonContent);
return ResultError.Fail("Not implemented!");
}
}