Skip to content

Commit 8d521f7

Browse files
committed
Fix 3rd party json
1 parent 15b341d commit 8d521f7

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

TwitchDownloaderWPF/PageChatRender.xaml.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ private void BackgroundRenderManager_DoWork(object sender, DoWorkEventArgs e)
9797
chatJson.streamer = new Streamer();
9898
chatJson.streamer.name = json["video"]["user_name"].ToString();
9999
chatJson.streamer.id = json["video"]["user_id"].ToObject<int>();
100+
chatJson.video.end = GenerateTimespan(json["video"]["duration"].ToString()).TotalSeconds;
100101
}
101102
chatJson.streamer.name = GetStreamerName(chatJson.streamer.id);
102103
}
@@ -275,6 +276,21 @@ private SKColor GenerateUserColor(SKColor userColor, SKColor background_color)
275276
return userColor;
276277
}
277278

279+
private TimeSpan GenerateTimespan(string input)
280+
{
281+
//There might be a better way to do this, gets string 0h0m0s and returns timespan
282+
TimeSpan returnSpan = new TimeSpan(0);
283+
string[] inputArray = input.Remove(input.Length - 1).Replace('h', ':').Replace('m', ':').Split(':');
284+
285+
returnSpan = returnSpan.Add(TimeSpan.FromSeconds(Int32.Parse(inputArray[inputArray.Length - 1])));
286+
if (inputArray.Length > 1)
287+
returnSpan = returnSpan.Add(TimeSpan.FromMinutes(Int32.Parse(inputArray[inputArray.Length - 2])));
288+
if (inputArray.Length > 2)
289+
returnSpan = returnSpan.Add(TimeSpan.FromHours(Int32.Parse(inputArray[inputArray.Length - 3])));
290+
291+
return returnSpan;
292+
}
293+
278294
private void RenderVideo(RenderOptions renderOptions, Queue<TwitchComment> finalComments, ChatRoot chatJson, object sender)
279295
{
280296
SKBitmap bufferBitmap = new SKBitmap(renderOptions.chat_width, renderOptions.chat_height);
@@ -285,7 +301,9 @@ private void RenderVideo(RenderOptions renderOptions, Queue<TwitchComment> final
285301
int duration;
286302
if (chatJson.video != null)
287303
{
288-
videoStart = (int)Math.Floor(chatJson.video.start);
304+
int startSeconds = (int)Math.Floor(chatJson.video.start);
305+
int firstCommentSeconds = (int)Math.Floor(chatJson.comments.First().content_offset_seconds);
306+
videoStart = startSeconds < firstCommentSeconds ? startSeconds : firstCommentSeconds;
289307
duration = (int)Math.Ceiling(chatJson.video.end) - videoStart;
290308
}
291309
else

TwitchDownloaderWPF/PageVodDownload.xaml.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,6 @@ private async void btnGetInfo_Click(object sender, RoutedEventArgs e)
137137
}
138138
}
139139

140-
private TimeSpan GenerateTimespan(string input)
141-
{
142-
//There might be a better way to do this, gets string 0h0m0s and returns timespan
143-
TimeSpan returnSpan = new TimeSpan(0);
144-
string[] inputArray = input.Remove(input.Length - 1).Replace('h', ':').Replace('m', ':').Split(':');
145-
146-
returnSpan = returnSpan.Add(TimeSpan.FromSeconds(Int32.Parse(inputArray[inputArray.Length - 1])));
147-
if (inputArray.Length > 1)
148-
returnSpan = returnSpan.Add(TimeSpan.FromMinutes(Int32.Parse(inputArray[inputArray.Length - 2])));
149-
if (inputArray.Length > 2)
150-
returnSpan = returnSpan.Add(TimeSpan.FromHours(Int32.Parse(inputArray[inputArray.Length - 3])));
151-
152-
return returnSpan;
153-
}
154-
155140
private async void btnDownload_Click(object sender, RoutedEventArgs e)
156141
{
157142
bool isValid = ValidateInput();

0 commit comments

Comments
 (0)