Skip to content

Commit

Permalink
Write embed videos in JSON export
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz authored and cooljeanius committed Nov 8, 2023
1 parent 0d18c90 commit bf8ed97
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,31 @@ private async ValueTask WriteUserAsync(User user, CancellationToken cancellation
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
Expand Down Expand Up @@ -224,6 +249,12 @@ await FormatMarkdownAsync(embed.Description ?? "", cancellationToken)
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");
Expand Down

0 comments on commit bf8ed97

Please sign in to comment.