@@ -489,6 +489,7 @@ private void SetAntiAlias(Graphics g)
489
489
private void GetEmotes ( List < KeyValuePair < int , Image > > chatEmotes , JToken comments , RenderOptions renderOptions )
490
490
{
491
491
List < int > alreadyAdded = new List < int > ( ) ;
492
+ List < int > failedEmotes = new List < int > ( ) ;
492
493
using ( WebClient client = new WebClient ( ) )
493
494
{
494
495
foreach ( var comment in comments )
@@ -498,20 +499,54 @@ private void GetEmotes(List<KeyValuePair<int, Image>> chatEmotes, JToken comment
498
499
if ( fragment [ "emoticon" ] != null )
499
500
{
500
501
int id = fragment [ "emoticon" ] [ "emoticon_id" ] . ToObject < int > ( ) ;
501
- if ( ! alreadyAdded . Contains ( id ) )
502
+ if ( ! alreadyAdded . Contains ( id ) && ! failedEmotes . Contains ( id ) )
502
503
{
503
- alreadyAdded . Add ( id ) ;
504
- byte [ ] bytes = client . DownloadData ( String . Format ( "https://static-cdn.jtvnw.net/emoticons/v1/{0}/1.0" , id ) ) ;
505
- MemoryStream ms = new MemoryStream ( bytes ) ;
506
- Image emoteImage = System . Drawing . Image . FromStream ( ms ) ;
507
- chatEmotes . Add ( new KeyValuePair < int , Image > ( id , emoteImage ) ) ;
504
+ try
505
+ {
506
+ byte [ ] bytes = client . DownloadData ( String . Format ( "https://static-cdn.jtvnw.net/emoticons/v1/{0}/1.0" , id ) ) ;
507
+ alreadyAdded . Add ( id ) ;
508
+ MemoryStream ms = new MemoryStream ( bytes ) ;
509
+ Image emoteImage = System . Drawing . Image . FromStream ( ms ) ;
510
+ chatEmotes . Add ( new KeyValuePair < int , Image > ( id , emoteImage ) ) ;
511
+ }
512
+ catch
513
+ {
514
+ string emoteName = fragment [ "text" ] . ToString ( ) ;
515
+ //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
516
+ try
517
+ {
518
+ HttpWebRequest request = ( HttpWebRequest ) WebRequest . Create ( "https://www.twitchmetrics.net/e/" + emoteName ) ;
519
+ request . AllowAutoRedirect = false ;
520
+ HttpWebResponse response = ( HttpWebResponse ) request . GetResponse ( ) ;
521
+ string redirUrl = response . Headers [ "Location" ] ;
522
+ response . Close ( ) ;
523
+ string newId = redirUrl . Split ( '/' ) . Last ( ) . Split ( '-' ) . First ( ) ;
524
+ byte [ ] bytes = client . DownloadData ( String . Format ( "https://static-cdn.jtvnw.net/emoticons/v1/{0}/1.0" , newId ) ) ;
525
+ alreadyAdded . Add ( id ) ;
526
+ MemoryStream ms = new MemoryStream ( bytes ) ;
527
+ Image emoteImage = System . Drawing . Image . FromStream ( ms ) ;
528
+ chatEmotes . Add ( new KeyValuePair < int , Image > ( id , emoteImage ) ) ;
529
+ }
530
+ catch
531
+ {
532
+ AppendLog ( "Unable to fetch emote " + emoteName ) ;
533
+ failedEmotes . Add ( id ) ;
534
+ }
535
+ }
508
536
}
509
537
}
510
538
}
511
539
}
512
540
}
513
541
}
514
542
543
+ private void AppendLog ( string message )
544
+ {
545
+ textLog . BeginInvoke ( ( Action ) ( ( ) =>
546
+ textLog . AppendText ( message + Environment . NewLine )
547
+ ) ) ;
548
+ }
549
+
515
550
private void DrawUsername ( Graphics g , RenderOptions renderOptions , Font nameFont , string userName , Color userColor , ref Size canvasSize , ref Point drawPos )
516
551
{
517
552
if ( renderOptions . outline )
0 commit comments