Skip to content

Commit c539d70

Browse files
committed
Fix cheermotes + Add channel specific cheermotes
1 parent bdb64b1 commit c539d70

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

TwitchDownloaderCore/ChatRenderer.cs

+15-11
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public async Task RenderVideoAsync(IProgress<ProgressReport> progress, Cancellat
5656
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Fetching 3rd Party Emotes" });
5757
List<TwitchEmote> thirdPartyEmotes = await Task.Run(() => TwitchHelper.GetThirdPartyEmotes(chatJson.streamer.id, cacheFolder, chatJson.emotes, renderOptions.BttvEmotes, renderOptions.FfzEmotes, renderOptions.StvEmotes));
5858
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Fetching Cheer Emotes" });
59-
List<CheerEmote> cheerEmotes = await Task.Run(() => TwitchHelper.GetBits(cacheFolder));
59+
List<CheerEmote> cheerEmotes = await Task.Run(() => TwitchHelper.GetBits(cacheFolder, chatJson.streamer.id.ToString()));
6060
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Fetching Emojis" });
6161
Dictionary<string, SKBitmap> emojiCache = await Task.Run(() => TwitchHelper.GetTwitterEmojis(chatJson.comments, cacheFolder));
6262

@@ -805,18 +805,22 @@ public static SKBitmap DrawMessage(SKBitmap sectionImage, List<SKBitmap> imageLi
805805
bool bitsPrinted = false;
806806
try
807807
{
808-
if (bitsCount > 0 && output.Any(char.IsDigit) && cheerEmotes.Any(x => output.Contains(x.prefix)))
808+
if (bitsCount > 0 && output.Any(char.IsDigit) && output.Any(char.IsLetter))
809809
{
810-
CheerEmote currentCheerEmote = cheerEmotes.Find(x => output.Contains(x.prefix));
811810
int bitsIndex = output.IndexOfAny("0123456789".ToCharArray());
812-
int bitsAmount = Int32.Parse(output.Substring(bitsIndex));
813-
bitsCount -= bitsAmount;
814-
KeyValuePair<int, TwitchEmote> tierList = currentCheerEmote.getTier(bitsAmount);
815-
GifEmote emote = new GifEmote(new Point(drawPos.X, drawPos.Y), tierList.Value.name, tierList.Value.codec, tierList.Value.imageScale, tierList.Value.emote_frames);
816-
currentGifEmotes.Add(emote);
817-
drawPos.X += (int)((tierList.Value.width / tierList.Value.imageScale) * renderOptions.EmoteScale + (3 * renderOptions.EmoteScale));
818-
sectionImage = DrawText(sectionImage, bitsAmount.ToString(), messageFont, imageList, renderOptions, currentGifEmotes, canvasSize, ref drawPos, true, default_x);
819-
bitsPrinted = true;
811+
string outputPrefix = output.Substring(0, bitsIndex).ToLower();
812+
if (cheerEmotes.Any(x => x.prefix.ToLower() == outputPrefix))
813+
{
814+
CheerEmote currentCheerEmote = cheerEmotes.Find(x => x.prefix.ToLower() == outputPrefix);
815+
int bitsAmount = Int32.Parse(output.Substring(bitsIndex));
816+
bitsCount -= bitsAmount;
817+
KeyValuePair<int, TwitchEmote> tierList = currentCheerEmote.getTier(bitsAmount);
818+
GifEmote emote = new GifEmote(new Point(drawPos.X, drawPos.Y), tierList.Value.name, tierList.Value.codec, tierList.Value.imageScale, tierList.Value.emote_frames);
819+
currentGifEmotes.Add(emote);
820+
drawPos.X += (int)((tierList.Value.width / tierList.Value.imageScale) * renderOptions.EmoteScale + (3 * renderOptions.EmoteScale));
821+
sectionImage = DrawText(sectionImage, bitsAmount.ToString(), messageFont, imageList, renderOptions, currentGifEmotes, canvasSize, ref drawPos, true, default_x);
822+
bitsPrinted = true;
823+
}
820824
}
821825
}
822826
catch

TwitchDownloaderCore/TwitchHelper.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public static Dictionary<string, SKBitmap> GetTwitterEmojis(List<Comment> commen
556556
return emojiCache;
557557
}
558558

559-
public static List<CheerEmote> GetBits(string cacheFolder)
559+
public static List<CheerEmote> GetBits(string cacheFolder, string channel_id = "")
560560
{
561561
List<CheerEmote> cheerEmotes = new List<CheerEmote>();
562562
string bitsFolder = Path.Combine(cacheFolder, "bits");
@@ -568,20 +568,20 @@ public static List<CheerEmote> GetBits(string cacheFolder)
568568
client.Headers.Add("Accept", "application/vnd.twitchtv.v5+json");
569569
client.Headers.Add("Client-ID", "kimne78kx3ncx6brgo4mv6wki5h1ko");
570570

571-
JObject globalCheer = JObject.Parse(client.DownloadString("https://api.twitch.tv/kraken/bits/actions"));
571+
JObject globalCheer = JObject.Parse(client.DownloadString("https://api.twitch.tv/kraken/bits/actions?channel_id=" + channel_id));
572572

573573
foreach (JToken emoteToken in globalCheer["actions"])
574574
{
575575
string prefix = emoteToken["prefix"].ToString();
576576
List<KeyValuePair<int, TwitchEmote>> tierList = new List<KeyValuePair<int, TwitchEmote>>();
577577
CheerEmote newEmote = new CheerEmote() { prefix = prefix, tierList = tierList };
578-
byte[] finalBytes = null;
579578
foreach (JToken tierToken in emoteToken["tiers"])
580579
{
581580
try
582581
{
583582
int minBits = tierToken["min_bits"].ToObject<int>();
584583
string fileName = Path.Combine(bitsFolder, prefix + minBits + "_2x.gif");
584+
byte[] finalBytes = null;
585585

586586
if (File.Exists(fileName))
587587
{

0 commit comments

Comments
 (0)