[CHANGE] Fixed auditing, storing images from account import
This commit is contained in:
@@ -2,6 +2,7 @@ namespace Manager.YouTube.Models.Innertube;
|
||||
|
||||
public class Channel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public bool NoIndex { get; set; }
|
||||
public bool Unlisted { get; set; }
|
||||
public bool FamilySafe { get; set; }
|
||||
|
@@ -6,6 +6,7 @@ namespace Manager.YouTube;
|
||||
public static class NetworkService
|
||||
{
|
||||
public const string Origin = "https://www.youtube.com";
|
||||
private static readonly HttpClient HttpClient = new HttpClient();
|
||||
|
||||
public static async Task<Result<string>> MakeRequestAsync(HttpRequestMessage request, YouTubeClient client, bool skipAuthenticationHeader = false)
|
||||
{
|
||||
@@ -32,8 +33,25 @@ public static class NetworkService
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<Result<byte[]>> DownloadBytesAsync(HttpRequestMessage request, YouTubeClient client)
|
||||
public static async Task<Result<DownloadResult>> DownloadBytesAsync(HttpRequestMessage request, YouTubeClient? client = null)
|
||||
{
|
||||
return ResultError.Fail("Not implemented");
|
||||
try
|
||||
{
|
||||
var response = client != null ? await client.HttpClient.SendAsync(request) : await HttpClient.SendAsync(request);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return ResultError.Fail($"Failed to get file to download, response code: {response.StatusCode}.");
|
||||
}
|
||||
|
||||
var data = await response.Content.ReadAsByteArrayAsync();;
|
||||
|
||||
return new DownloadResult(data, response.Content.Headers.ContentType?.MediaType, response.Content.Headers.ContentDisposition?.FileName?.Trim('"'), response.Content.Headers.ContentLength ?? 0);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ResultError.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public record DownloadResult(byte[] Data, string? ContentType, string? FileName, long ContentLength);
|
@@ -4,18 +4,30 @@ using Manager.YouTube.Models.Innertube;
|
||||
|
||||
namespace Manager.YouTube.Parsers.Json;
|
||||
|
||||
/// <summary>
|
||||
/// Parsing functionality for the response from the innertube browse endpoint.
|
||||
/// </summary>
|
||||
public static class ChannelJsonParser
|
||||
{
|
||||
public static Result<Channel> ParseJsonToChannelData(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
var channel = new Channel();
|
||||
var doc = JsonDocument.Parse(json);
|
||||
var rootDoc = doc.RootElement;
|
||||
|
||||
var channelMetadata = rootDoc
|
||||
.GetProperty("metadata")
|
||||
.GetProperty("channelMetadataRenderer");
|
||||
|
||||
var channelId = channelMetadata.GetProperty("externalId").GetString();
|
||||
if (channelId == null)
|
||||
{
|
||||
throw new InvalidOperationException("No channel id found.");
|
||||
}
|
||||
|
||||
var channel = new Channel
|
||||
{
|
||||
Id = channelId,
|
||||
ChannelName = channelMetadata.GetProperty("title").ToString(),
|
||||
};
|
||||
|
||||
var microformat = rootDoc.GetProperty("microformat").GetProperty("microformatDataRenderer");
|
||||
|
||||
@@ -29,11 +41,6 @@ public static class ChannelJsonParser
|
||||
channel.Unlisted = microformat.GetProperty("unlisted").GetBoolean();
|
||||
channel.FamilySafe = microformat.GetProperty("familySafe").GetBoolean();
|
||||
|
||||
var channelMetadata = rootDoc
|
||||
.GetProperty("metadata")
|
||||
.GetProperty("channelMetadataRenderer");
|
||||
channel.ChannelName = channelMetadata.GetProperty("title").GetString();
|
||||
|
||||
var avatarThumbnails = channelMetadata.GetProperty("avatar")
|
||||
.GetProperty("thumbnails")
|
||||
.EnumerateArray();
|
||||
|
Reference in New Issue
Block a user