Skip to content

Commit

Permalink
Fix 3rd party json
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Jun 23, 2020
1 parent 15b341d commit 8d521f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
20 changes: 19 additions & 1 deletion TwitchDownloaderWPF/PageChatRender.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ private void BackgroundRenderManager_DoWork(object sender, DoWorkEventArgs e)
chatJson.streamer = new Streamer();
chatJson.streamer.name = json["video"]["user_name"].ToString();
chatJson.streamer.id = json["video"]["user_id"].ToObject<int>();
chatJson.video.end = GenerateTimespan(json["video"]["duration"].ToString()).TotalSeconds;
}
chatJson.streamer.name = GetStreamerName(chatJson.streamer.id);
}
Expand Down Expand Up @@ -275,6 +276,21 @@ private SKColor GenerateUserColor(SKColor userColor, SKColor background_color)
return userColor;
}

private TimeSpan GenerateTimespan(string input)
{
//There might be a better way to do this, gets string 0h0m0s and returns timespan
TimeSpan returnSpan = new TimeSpan(0);
string[] inputArray = input.Remove(input.Length - 1).Replace('h', ':').Replace('m', ':').Split(':');

returnSpan = returnSpan.Add(TimeSpan.FromSeconds(Int32.Parse(inputArray[inputArray.Length - 1])));
if (inputArray.Length > 1)
returnSpan = returnSpan.Add(TimeSpan.FromMinutes(Int32.Parse(inputArray[inputArray.Length - 2])));
if (inputArray.Length > 2)
returnSpan = returnSpan.Add(TimeSpan.FromHours(Int32.Parse(inputArray[inputArray.Length - 3])));

return returnSpan;
}

private void RenderVideo(RenderOptions renderOptions, Queue<TwitchComment> finalComments, ChatRoot chatJson, object sender)
{
SKBitmap bufferBitmap = new SKBitmap(renderOptions.chat_width, renderOptions.chat_height);
Expand All @@ -285,7 +301,9 @@ private void RenderVideo(RenderOptions renderOptions, Queue<TwitchComment> final
int duration;
if (chatJson.video != null)
{
videoStart = (int)Math.Floor(chatJson.video.start);
int startSeconds = (int)Math.Floor(chatJson.video.start);
int firstCommentSeconds = (int)Math.Floor(chatJson.comments.First().content_offset_seconds);
videoStart = startSeconds < firstCommentSeconds ? startSeconds : firstCommentSeconds;
duration = (int)Math.Ceiling(chatJson.video.end) - videoStart;
}
else
Expand Down
15 changes: 0 additions & 15 deletions TwitchDownloaderWPF/PageVodDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,6 @@ private async void btnGetInfo_Click(object sender, RoutedEventArgs e)
}
}

private TimeSpan GenerateTimespan(string input)
{
//There might be a better way to do this, gets string 0h0m0s and returns timespan
TimeSpan returnSpan = new TimeSpan(0);
string[] inputArray = input.Remove(input.Length - 1).Replace('h', ':').Replace('m', ':').Split(':');

returnSpan = returnSpan.Add(TimeSpan.FromSeconds(Int32.Parse(inputArray[inputArray.Length - 1])));
if (inputArray.Length > 1)
returnSpan = returnSpan.Add(TimeSpan.FromMinutes(Int32.Parse(inputArray[inputArray.Length - 2])));
if (inputArray.Length > 2)
returnSpan = returnSpan.Add(TimeSpan.FromHours(Int32.Parse(inputArray[inputArray.Length - 3])));

return returnSpan;
}

private async void btnDownload_Click(object sender, RoutedEventArgs e)
{
bool isValid = ValidateInput();
Expand Down

0 comments on commit 8d521f7

Please sign in to comment.