[CHANGE] Split up json parsing, added getting account info
This commit is contained in:
@@ -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!");
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user