[CHANGE] Finished impl required data for client

This commit is contained in:
max
2025-09-08 01:40:43 +02:00
parent b2c6003203
commit b2c9fc2c52
10 changed files with 199 additions and 228 deletions

View File

@@ -9,25 +9,26 @@ namespace Manager.YouTube.Parsers.Json;
/// </summary>
public static class ChannelJsonParser
{
public static Result<ChannelFetch> ParseJsonToChannelData(string json)
public static Result<Channel> ParseJsonToChannelData(string json)
{
try
{
var channel = new Channel();
var doc = JsonDocument.Parse(json);
var rootDoc = doc.RootElement;
var microformat = rootDoc.GetProperty("microformat").GetProperty("microformatDataRenderer");
var availableCountries = microformat
channel.AvailableCountries = microformat
.GetProperty("availableCountries")
.EnumerateArray()
.Select(e => e.GetString())
.ToList();
var description = microformat.GetProperty("description").GetString();
var noIndex = microformat.GetProperty("noindex").GetBoolean();
var unlisted = microformat.GetProperty("unlisted").GetBoolean();
var familySafe = microformat.GetProperty("familySafe").GetBoolean();
.OfType<string>().ToList();
channel.Description = microformat.GetProperty("description").GetString();
channel.NoIndex = microformat.GetProperty("noindex").GetBoolean();
channel.Unlisted = microformat.GetProperty("unlisted").GetBoolean();
channel.FamilySafe = microformat.GetProperty("familySafe").GetBoolean();
channel.ChannelName = microformat.GetProperty("title").GetString();
var avatarThumbnails = rootDoc
.GetProperty("metadata")
@@ -35,15 +36,14 @@ public static class ChannelJsonParser
.GetProperty("avatar")
.GetProperty("thumbnails")
.EnumerateArray();
var avatars = JsonParser.ParseImages(avatarThumbnails);
channel.AvatarImages = JsonParser.ParseImages(avatarThumbnails);
var headerContent = rootDoc
.GetProperty("header")
.GetProperty("pageHeaderRenderer")
.GetProperty("content");
var metadataPartHandle = headerContent
channel.Handle = headerContent
.GetProperty("pageHeaderViewModel")
.GetProperty("metadata")
.GetProperty("contentMetadataViewModel")
@@ -63,21 +63,9 @@ public static class ChannelJsonParser
.GetProperty("image")
.GetProperty("sources")
.EnumerateArray();
var banners = JsonParser.ParseImages(bannerImages);
var resultFetch = new ChannelFetch
{
NoIndex = noIndex,
Unlisted = unlisted,
FamilySafe = familySafe,
Handle = metadataPartHandle,
Description = description,
AvailableCountries = availableCountries.OfType<string>().ToList(),
AvatarImages = avatars,
BannerImages = banners
};
return resultFetch;
channel.BannerImages = JsonParser.ParseImages(bannerImages);
return channel;
}
catch (Exception e)
{