Skip to content

Commit

Permalink
Fix cheermotes + Add channel specific cheermotes
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Oct 5, 2021
1 parent bdb64b1 commit c539d70
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
26 changes: 15 additions & 11 deletions TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task RenderVideoAsync(IProgress<ProgressReport> progress, Cancellat
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Fetching 3rd Party Emotes" });
List<TwitchEmote> 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<CheerEmote> cheerEmotes = await Task.Run(() => TwitchHelper.GetBits(cacheFolder));
List<CheerEmote> cheerEmotes = await Task.Run(() => TwitchHelper.GetBits(cacheFolder, chatJson.streamer.id.ToString()));
progress.Report(new ProgressReport() { reportType = ReportType.Message, data = "Fetching Emojis" });
Dictionary<string, SKBitmap> emojiCache = await Task.Run(() => TwitchHelper.GetTwitterEmojis(chatJson.comments, cacheFolder));

Expand Down Expand Up @@ -805,18 +805,22 @@ public static SKBitmap DrawMessage(SKBitmap sectionImage, List<SKBitmap> 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<int, TwitchEmote> 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<int, TwitchEmote> 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
Expand Down
6 changes: 3 additions & 3 deletions TwitchDownloaderCore/TwitchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public static Dictionary<string, SKBitmap> GetTwitterEmojis(List<Comment> commen
return emojiCache;
}

public static List<CheerEmote> GetBits(string cacheFolder)
public static List<CheerEmote> GetBits(string cacheFolder, string channel_id = "")
{
List<CheerEmote> cheerEmotes = new List<CheerEmote>();
string bitsFolder = Path.Combine(cacheFolder, "bits");
Expand All @@ -568,20 +568,20 @@ public static List<CheerEmote> 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<KeyValuePair<int, TwitchEmote>> tierList = new List<KeyValuePair<int, TwitchEmote>>();
CheerEmote newEmote = new CheerEmote() { prefix = prefix, tierList = tierList };
byte[] finalBytes = null;
foreach (JToken tierToken in emoteToken["tiers"])
{
try
{
int minBits = tierToken["min_bits"].ToObject<int>();
string fileName = Path.Combine(bitsFolder, prefix + minBits + "_2x.gif");
byte[] finalBytes = null;

if (File.Exists(fileName))
{
Expand Down

0 comments on commit c539d70

Please sign in to comment.