@@ -97,6 +97,7 @@ private void BackgroundRenderManager_DoWork(object sender, DoWorkEventArgs e)
97
97
chatJson . streamer = new Streamer ( ) ;
98
98
chatJson . streamer . name = json [ "video" ] [ "user_name" ] . ToString ( ) ;
99
99
chatJson . streamer . id = json [ "video" ] [ "user_id" ] . ToObject < int > ( ) ;
100
+ chatJson . video . end = GenerateTimespan ( json [ "video" ] [ "duration" ] . ToString ( ) ) . TotalSeconds ;
100
101
}
101
102
chatJson . streamer . name = GetStreamerName ( chatJson . streamer . id ) ;
102
103
}
@@ -275,6 +276,21 @@ private SKColor GenerateUserColor(SKColor userColor, SKColor background_color)
275
276
return userColor ;
276
277
}
277
278
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
+
278
294
private void RenderVideo ( RenderOptions renderOptions , Queue < TwitchComment > finalComments , ChatRoot chatJson , object sender )
279
295
{
280
296
SKBitmap bufferBitmap = new SKBitmap ( renderOptions . chat_width , renderOptions . chat_height ) ;
@@ -285,7 +301,9 @@ private void RenderVideo(RenderOptions renderOptions, Queue<TwitchComment> final
285
301
int duration ;
286
302
if ( chatJson . video != null )
287
303
{
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 ;
289
307
duration = ( int ) Math . Ceiling ( chatJson . video . end ) - videoStart ;
290
308
}
291
309
else
0 commit comments