Skip to content

Commit

Permalink
Waybackmachine backup for old emotes
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Oct 25, 2019
1 parent 3cad34c commit ef3a3ea
Showing 1 changed file with 50 additions and 14 deletions.
64 changes: 50 additions & 14 deletions TwitchDownloaderWPF/PageChatRender.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -880,24 +880,60 @@ private void GetEmotes(Dictionary<string, SKBitmap> chatEmotes, List<Comment> co
catch
{
string emoteName = fragment.text;
//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
//lets try waybackmachine, very slow though :(
bool foundEmote = false;

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);
SKBitmap emoteImage = SKBitmap.Decode(ms);
chatEmotes.Add(id, emoteImage);
for (int i = 1; i <= 3; i++)
{
JObject response = JObject.Parse(client.DownloadString($"https://archive.org/wayback/available?url=https://static-cdn.jtvnw.net/emoticons/v1/{id}/{i}.0/"));
if (response["archived_snapshots"]["closest"] != null && response["archived_snapshots"]["closest"]["available"].ToObject<bool>() == true)
{
byte[] bytes = client.DownloadData(response["archived_snapshots"]["closest"]["url"].ToString().Replace("/https://static-cdn.jtvnw.net", "if_/https://static-cdn.jtvnw.net"));
MemoryStream ms = new MemoryStream(bytes);
SKBitmap emoteImage = SKBitmap.Decode(ms);
SKBitmap emoteImageScaled = new SKBitmap(28, 28);
emoteImage.ScalePixels(emoteImageScaled, SKFilterQuality.High);
alreadyAdded.Add(id);
chatEmotes.Add(id, emoteImageScaled);
emoteImage.Dispose();
foundEmote = true;
break;
}
}
}
catch { }


if (foundEmote)
continue;
else
{
//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);
SKBitmap emoteImage = SKBitmap.Decode(ms);
chatEmotes.Add(id, emoteImage);
foundEmote = true;
}
catch
{

}
}
catch
if (!foundEmote)
{
AppendLog("Unable to fetch emote " + emoteName);
AppendLog($"Unable to fetch emote {emoteName}(ID:{id})");
failedEmotes.Add(id);
}
}
Expand Down

0 comments on commit ef3a3ea

Please sign in to comment.