From ca18152c898d9b0de748aba35114ccdd4102594e Mon Sep 17 00:00:00 2001 From: lay295 Date: Thu, 17 Sep 2020 03:24:12 -0400 Subject: [PATCH] Add a little badge easter egg for my username --- TwitchDownloaderCLI/README.md | 2 +- TwitchDownloaderCore/ChatRenderer.cs | 19 ++++++++++++++++++- TwitchDownloaderCore/TwitchHelper.cs | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/TwitchDownloaderCLI/README.md b/TwitchDownloaderCLI/README.md index 4dba7a04..6f427d80 100644 --- a/TwitchDownloaderCLI/README.md +++ b/TwitchDownloaderCLI/README.md @@ -92,7 +92,7 @@ Path to JSON chat file input. (Default: 4) Size of outline if outline is enabled. **-f/-\-font** -(Default: Ariel) Font to use. +(Default: Arial) Font to use. **-\-font-size** (Default: 12) Size of font. diff --git a/TwitchDownloaderCore/ChatRenderer.cs b/TwitchDownloaderCore/ChatRenderer.cs index 298f3a99..02259c5d 100644 --- a/TwitchDownloaderCore/ChatRenderer.cs +++ b/TwitchDownloaderCore/ChatRenderer.cs @@ -463,6 +463,24 @@ public static SKBitmap DrawTimestamp(SKBitmap sectionImage, List image } public SKBitmap DrawBadges(SKBitmap sectionImage, List imageList, ChatRenderOptions renderOptions, List chatBadges, Comment comment, Size canvasSize, ref Point drawPos) { + //A little easter egg for my Twitch username won't hurt :) + if (comment.commenter.name == "ilovekeepo69" && chatBadges.Any(x => x.Name == "ilovekeepo69")) + { + SKBitmap badgeImage = chatBadges.Where(x => x.Name == "ilovekeepo69").First().Versions["1"]; + using (SKCanvas sectionImageCanvas = new SKCanvas(sectionImage)) + { + float imageRatio = (float)(renderOptions.EmoteScale * 0.5); + float imageSize = badgeImage.Width * imageRatio; + float left = (float)drawPos.X; + float right = imageSize + left; + float top = (float)((sectionImage.Height - imageSize) / 2); + float bottom = imageSize + top; + SKRect drawBox = new SKRect(left, top, right, bottom); + sectionImageCanvas.DrawBitmap(badgeImage, drawBox, imagePaint); + drawPos.X += (int)Math.Floor(20 * renderOptions.EmoteScale); + } + } + if (comment.message.user_badges != null) { foreach (var badge in comment.message.user_badges) @@ -502,7 +520,6 @@ public SKBitmap DrawBadges(SKBitmap sectionImage, List imageList, Chat } } } - return sectionImage; } public static SKBitmap DrawUsername(SKBitmap sectionImage, List imageList, ChatRenderOptions renderOptions, SKPaint nameFont, string userName, SKColor userColor, Size canvasSize, ref Point drawPos) diff --git a/TwitchDownloaderCore/TwitchHelper.cs b/TwitchDownloaderCore/TwitchHelper.cs index 6a4a893b..87779ca0 100644 --- a/TwitchDownloaderCore/TwitchHelper.cs +++ b/TwitchDownloaderCore/TwitchHelper.cs @@ -397,6 +397,20 @@ public static List GetChatBadges(int streamerId) chatBadges.Add(new ChatBadge() { Name = name, Versions = versions }); } + + try + { + byte[] bytes = client.DownloadData("https://cdn.betterttv.net/emote/58493695987aab42df852e0f/2x"); + MemoryStream ms = new MemoryStream(bytes); + SKBitmap badgeImage = SKBitmap.Decode(ms); + SKBitmap scaledBitmap = new SKBitmap(36, 36); + using (SKCanvas canvas = new SKCanvas(scaledBitmap)) + { + canvas.DrawBitmap(badgeImage, new SKRect(0, 0, 36, 36), new SKPaint()); + } + chatBadges.Add(new ChatBadge() { Name = "ilovekeepo69", Versions = new Dictionary() { { "1", scaledBitmap } } }); + } + catch { } } return chatBadges;