From c539d704e169ac93d7293f15ada2577559c4eefc Mon Sep 17 00:00:00 2001 From: lay295 Date: Mon, 4 Oct 2021 21:17:42 -0400 Subject: [PATCH] Fix cheermotes + Add channel specific cheermotes --- TwitchDownloaderCore/ChatRenderer.cs | 26 +++++++++++++++----------- TwitchDownloaderCore/TwitchHelper.cs | 6 +++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/TwitchDownloaderCore/ChatRenderer.cs b/TwitchDownloaderCore/ChatRenderer.cs index 71e67c93..2f835cb3 100644 --- a/TwitchDownloaderCore/ChatRenderer.cs +++ b/TwitchDownloaderCore/ChatRenderer.cs @@ -56,7 +56,7 @@ public async Task RenderVideoAsync(IProgress progress, Cancellat progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Fetching 3rd Party Emotes" }); List thirdPartyEmotes = await Task.Run(() => TwitchHelper.GetThirdPartyEmotes(chatJson.streamer.id, cacheFolder, chatJson.emotes, renderOptions.BttvEmotes, renderOptions.FfzEmotes, renderOptions.StvEmotes)); progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Fetching Cheer Emotes" }); - List cheerEmotes = await Task.Run(() => TwitchHelper.GetBits(cacheFolder)); + List cheerEmotes = await Task.Run(() => TwitchHelper.GetBits(cacheFolder, chatJson.streamer.id.ToString())); progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Fetching Emojis" }); Dictionary emojiCache = await Task.Run(() => TwitchHelper.GetTwitterEmojis(chatJson.comments, cacheFolder)); @@ -805,18 +805,22 @@ public static SKBitmap DrawMessage(SKBitmap sectionImage, List imageLi bool bitsPrinted = false; try { - if (bitsCount > 0 && output.Any(char.IsDigit) && cheerEmotes.Any(x => output.Contains(x.prefix))) + if (bitsCount > 0 && output.Any(char.IsDigit) && output.Any(char.IsLetter)) { - CheerEmote currentCheerEmote = cheerEmotes.Find(x => output.Contains(x.prefix)); int bitsIndex = output.IndexOfAny("0123456789".ToCharArray()); - int bitsAmount = Int32.Parse(output.Substring(bitsIndex)); - bitsCount -= bitsAmount; - KeyValuePair tierList = currentCheerEmote.getTier(bitsAmount); - GifEmote emote = new GifEmote(new Point(drawPos.X, drawPos.Y), tierList.Value.name, tierList.Value.codec, tierList.Value.imageScale, tierList.Value.emote_frames); - currentGifEmotes.Add(emote); - drawPos.X += (int)((tierList.Value.width / tierList.Value.imageScale) * renderOptions.EmoteScale + (3 * renderOptions.EmoteScale)); - sectionImage = DrawText(sectionImage, bitsAmount.ToString(), messageFont, imageList, renderOptions, currentGifEmotes, canvasSize, ref drawPos, true, default_x); - bitsPrinted = true; + string outputPrefix = output.Substring(0, bitsIndex).ToLower(); + if (cheerEmotes.Any(x => x.prefix.ToLower() == outputPrefix)) + { + CheerEmote currentCheerEmote = cheerEmotes.Find(x => x.prefix.ToLower() == outputPrefix); + int bitsAmount = Int32.Parse(output.Substring(bitsIndex)); + bitsCount -= bitsAmount; + KeyValuePair tierList = currentCheerEmote.getTier(bitsAmount); + GifEmote emote = new GifEmote(new Point(drawPos.X, drawPos.Y), tierList.Value.name, tierList.Value.codec, tierList.Value.imageScale, tierList.Value.emote_frames); + currentGifEmotes.Add(emote); + drawPos.X += (int)((tierList.Value.width / tierList.Value.imageScale) * renderOptions.EmoteScale + (3 * renderOptions.EmoteScale)); + sectionImage = DrawText(sectionImage, bitsAmount.ToString(), messageFont, imageList, renderOptions, currentGifEmotes, canvasSize, ref drawPos, true, default_x); + bitsPrinted = true; + } } } catch diff --git a/TwitchDownloaderCore/TwitchHelper.cs b/TwitchDownloaderCore/TwitchHelper.cs index 0a039ae4..ccb9fde9 100644 --- a/TwitchDownloaderCore/TwitchHelper.cs +++ b/TwitchDownloaderCore/TwitchHelper.cs @@ -556,7 +556,7 @@ public static Dictionary GetTwitterEmojis(List commen return emojiCache; } - public static List GetBits(string cacheFolder) + public static List GetBits(string cacheFolder, string channel_id = "") { List cheerEmotes = new List(); string bitsFolder = Path.Combine(cacheFolder, "bits"); @@ -568,20 +568,20 @@ public static List GetBits(string cacheFolder) client.Headers.Add("Accept", "application/vnd.twitchtv.v5+json"); client.Headers.Add("Client-ID", "kimne78kx3ncx6brgo4mv6wki5h1ko"); - JObject globalCheer = JObject.Parse(client.DownloadString("https://api.twitch.tv/kraken/bits/actions")); + JObject globalCheer = JObject.Parse(client.DownloadString("https://api.twitch.tv/kraken/bits/actions?channel_id=" + channel_id)); foreach (JToken emoteToken in globalCheer["actions"]) { string prefix = emoteToken["prefix"].ToString(); List> tierList = new List>(); CheerEmote newEmote = new CheerEmote() { prefix = prefix, tierList = tierList }; - byte[] finalBytes = null; foreach (JToken tierToken in emoteToken["tiers"]) { try { int minBits = tierToken["min_bits"].ToObject(); string fileName = Path.Combine(bitsFolder, prefix + minBits + "_2x.gif"); + byte[] finalBytes = null; if (File.Exists(fileName)) {