Skip to content

Commit

Permalink
Add a little badge easter egg for my username
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Sep 17, 2020
1 parent a1fa85a commit ca18152
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion TwitchDownloaderCLI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 18 additions & 1 deletion TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,24 @@ public static SKBitmap DrawTimestamp(SKBitmap sectionImage, List<SKBitmap> image
}
public SKBitmap DrawBadges(SKBitmap sectionImage, List<SKBitmap> imageList, ChatRenderOptions renderOptions, List<ChatBadge> 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)
Expand Down Expand Up @@ -502,7 +520,6 @@ public SKBitmap DrawBadges(SKBitmap sectionImage, List<SKBitmap> imageList, Chat
}
}
}

return sectionImage;
}
public static SKBitmap DrawUsername(SKBitmap sectionImage, List<SKBitmap> imageList, ChatRenderOptions renderOptions, SKPaint nameFont, string userName, SKColor userColor, Size canvasSize, ref Point drawPos)
Expand Down
14 changes: 14 additions & 0 deletions TwitchDownloaderCore/TwitchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,20 @@ public static List<ChatBadge> 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<string, SKBitmap>() { { "1", scaledBitmap } } });
}
catch { }
}

return chatBadges;
Expand Down

0 comments on commit ca18152

Please sign in to comment.