diff --git a/TwitchDownloader/frmChatRender.Designer.cs b/TwitchDownloader/frmChatRender.Designer.cs index 674b7dbc..b7b1ebd3 100644 --- a/TwitchDownloader/frmChatRender.Designer.cs +++ b/TwitchDownloader/frmChatRender.Designer.cs @@ -256,7 +256,7 @@ private void InitializeComponent() // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(808, 76); + this.label6.Location = new System.Drawing.Point(745, 33); this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(40, 17); @@ -265,11 +265,11 @@ private void InitializeComponent() // // textLog // - this.textLog.Location = new System.Drawing.Point(812, 96); + this.textLog.Location = new System.Drawing.Point(748, 59); this.textLog.Margin = new System.Windows.Forms.Padding(4); this.textLog.Multiline = true; this.textLog.Name = "textLog"; - this.textLog.Size = new System.Drawing.Size(232, 324); + this.textLog.Size = new System.Drawing.Size(296, 361); this.textLog.TabIndex = 68; // // label1 diff --git a/TwitchDownloader/frmChatRender.cs b/TwitchDownloader/frmChatRender.cs index 1434f394..28c3126f 100644 --- a/TwitchDownloader/frmChatRender.cs +++ b/TwitchDownloader/frmChatRender.cs @@ -489,6 +489,7 @@ private void SetAntiAlias(Graphics g) private void GetEmotes(List> chatEmotes, JToken comments, RenderOptions renderOptions) { List alreadyAdded = new List(); + List failedEmotes = new List(); using (WebClient client = new WebClient()) { foreach (var comment in comments) @@ -498,13 +499,40 @@ private void GetEmotes(List> chatEmotes, JToken comment if (fragment["emoticon"] != null) { int id = fragment["emoticon"]["emoticon_id"].ToObject(); - if (!alreadyAdded.Contains(id)) + if (!alreadyAdded.Contains(id) && !failedEmotes.Contains(id)) { - alreadyAdded.Add(id); - byte[] bytes = client.DownloadData(String.Format("https://static-cdn.jtvnw.net/emoticons/v1/{0}/1.0", id)); - MemoryStream ms = new MemoryStream(bytes); - Image emoteImage = System.Drawing.Image.FromStream(ms); - chatEmotes.Add(new KeyValuePair(id, emoteImage)); + try + { + byte[] bytes = client.DownloadData(String.Format("https://static-cdn.jtvnw.net/emoticons/v1/{0}/1.0", id)); + alreadyAdded.Add(id); + MemoryStream ms = new MemoryStream(bytes); + Image emoteImage = System.Drawing.Image.FromStream(ms); + chatEmotes.Add(new KeyValuePair(id, emoteImage)); + } + catch + { + string emoteName = fragment["text"].ToString(); + //sometimes emote still exists but id is different, I use twitch metrics because I can't find an api to find an emote by name + try + { + HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.twitchmetrics.net/e/" + emoteName); + request.AllowAutoRedirect = false; + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + string redirUrl = response.Headers["Location"]; + response.Close(); + string newId = redirUrl.Split('/').Last().Split('-').First(); + byte[] bytes = client.DownloadData(String.Format("https://static-cdn.jtvnw.net/emoticons/v1/{0}/1.0", newId)); + alreadyAdded.Add(id); + MemoryStream ms = new MemoryStream(bytes); + Image emoteImage = System.Drawing.Image.FromStream(ms); + chatEmotes.Add(new KeyValuePair(id, emoteImage)); + } + catch + { + AppendLog("Unable to fetch emote " + emoteName); + failedEmotes.Add(id); + } + } } } } @@ -512,6 +540,13 @@ private void GetEmotes(List> chatEmotes, JToken comment } } + private void AppendLog(string message) + { + textLog.BeginInvoke((Action)(() => + textLog.AppendText(message + Environment.NewLine) + )); + } + private void DrawUsername(Graphics g, RenderOptions renderOptions, Font nameFont, string userName, Color userColor, ref Size canvasSize, ref Point drawPos) { if (renderOptions.outline)