From 4f6e6f4f0b5a42b6c17e3cc34b8013c4624a83aa Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Tue, 7 Nov 2023 16:03:39 +0200 Subject: [PATCH] Write embed videos in JSON export Closes #1120 --- .../Exporting/JsonMessageWriter.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs b/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs index 0c59e3e..ac25510 100644 --- a/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs +++ b/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs @@ -143,6 +143,31 @@ internal class JsonMessageWriter : MessageWriter await _writer.FlushAsync(cancellationToken); } + private async ValueTask WriteEmbedVideoAsync( + EmbedVideo embedVideo, + CancellationToken cancellationToken = default + ) + { + _writer.WriteStartObject(); + + if (!string.IsNullOrWhiteSpace(embedVideo.Url)) + { + _writer.WriteString( + "url", + await Context.ResolveAssetUrlAsync( + embedVideo.ProxyUrl ?? embedVideo.Url, + cancellationToken + ) + ); + } + + _writer.WriteNumber("width", embedVideo.Width); + _writer.WriteNumber("height", embedVideo.Height); + + _writer.WriteEndObject(); + await _writer.FlushAsync(cancellationToken); + } + private async ValueTask WriteEmbedFooterAsync( EmbedFooter embedFooter, CancellationToken cancellationToken = default @@ -224,6 +249,12 @@ internal class JsonMessageWriter : MessageWriter await WriteEmbedImageAsync(embed.Image, cancellationToken); } + if (embed.Video is not null) + { + _writer.WritePropertyName("video"); + await WriteEmbedVideoAsync(embed.Video, cancellationToken); + } + if (embed.Footer is not null) { _writer.WritePropertyName("footer");