Skip to content

Commit

Permalink
Get name from user id incase streamer changes name (like moonmoon)
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Oct 27, 2019
1 parent 111dfb6 commit ec40f4e
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions TwitchDownloaderWPF/PageChatRender.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ private void BackgroundRenderManager_DoWork(object sender, DoWorkEventArgs e)
try
{
chatJson = JsonConvert.DeserializeObject<ChatRoot>(File.ReadAllText(renderOptions.json_path));
chatJson.streamer.name = GetStreamerName(chatJson.streamer.id);
}
catch (JsonSerializationException)
{
chatJson = new ChatRoot();
chatJson.comments = JsonConvert.DeserializeObject<List<Comment>>(File.ReadAllText(renderOptions.json_path));
chatJson.streamer = new Streamer();
chatJson.streamer.id = Int32.Parse(chatJson.comments.First().channel_id);
chatJson.streamer.name = "";
chatJson.streamer.name = GetStreamerName(chatJson.streamer.id);
}
BlockingCollection<TwitchComment> finalComments = new BlockingCollection<TwitchComment>();
List<ThirdPartyEmote> thirdPartyEmotes = new List<ThirdPartyEmote>();
Expand Down Expand Up @@ -202,6 +203,22 @@ private void BackgroundRenderManager_DoWork(object sender, DoWorkEventArgs e)
}
}

private string GetStreamerName(int id)
{
try
{
using (WebClient client = new WebClient())
{
client.Headers.Add("Accept", "application/vnd.twitchtv.v5+json; charset=UTF-8");
client.Headers.Add("Client-Id", "kimne78kx3ncx6brgo4mv6wki5h1ko");

JObject response = JObject.Parse(client.DownloadString("https://api.twitch.tv/kraken/users/" + id));
return response["name"].ToString();
}
}
catch { return ""; }
}

private SKColor GenerateUserColor(SKColor userColor, SKColor background_color)
{
//I don't really know much about this, but i'll give it a shot
Expand All @@ -212,7 +229,10 @@ private SKColor GenerateUserColor(SKColor userColor, SKColor background_color)

if (Math.Abs(userColorHsl[2] - backgroundColorHsl[2]) < 10)
{
userColorHsl[2] += 50;
if (backgroundColorHsl[2] < 50)
userColorHsl[2] += 50;
else
userColorHsl[2] -= 50;
SKColor newColor = SKColor.FromHsl(userColorHsl[0], userColorHsl[1], userColorHsl[2]);
return newColor;
}
Expand Down

0 comments on commit ec40f4e

Please sign in to comment.