@@ -52,7 +52,9 @@ func millisToSubRipTs(millis Millis) string {
5252
5353type ChatMessage struct {
5454 TimeOffset Millis
55- Text string
55+ Nickname string
56+ Color string
57+ Text_ string
5658}
5759
5860type Chunk struct {
@@ -304,6 +306,9 @@ func sliceChatLog(chatLog []ChatMessage, start, end Millis) []ChatMessage {
304306}
305307
306308// IMPORTANT! chatLog is assumed to be sorted by TimeOffset.
309+ // TODO: chat log compression does not make sense anymore
310+ // We need to introduce ChatMessage groups instead of concatinating rendering messages
311+ /*
307312func compressChatLog(chatLog []ChatMessage) []ChatMessage {
308313 result := []ChatMessage{}
309314 for i := range chatLog {
@@ -315,6 +320,7 @@ func compressChatLog(chatLog []ChatMessage) []ChatMessage {
315320 }
316321 return result
317322}
323+ */
318324
319325type Func struct {
320326 Description string
@@ -353,6 +359,7 @@ func loadTwitchChatDownloaderCSVButParseManually(path string) ([]ChatMessage, er
353359 nickname := pair [0 ]
354360
355361 pair = strings .SplitN (pair [1 ], "," , 2 )
362+ color := pair [0 ]
356363 text := pair [1 ]
357364
358365 if len (text ) >= 2 && text [0 ] == '"' && text [len (text )- 1 ] == '"' {
@@ -361,15 +368,17 @@ func loadTwitchChatDownloaderCSVButParseManually(path string) ([]ChatMessage, er
361368
362369 chatLog = append (chatLog , ChatMessage {
363370 TimeOffset : Millis (secs * 1000 ),
364- Text : fmt .Sprintf ("[%s] %s" , nickname , text ),
371+ Color : color ,
372+ Nickname : nickname ,
373+ Text_ : text ,
365374 })
366375 }
367376
368377 sort .Slice (chatLog , func (i , j int ) bool {
369378 return chatLog [i ].TimeOffset < chatLog [j ].TimeOffset
370379 })
371380
372- return compressChatLog ( chatLog ) , nil
381+ return chatLog , nil
373382}
374383
375384func (context * EvalContext ) evalMarkutContent (content string , path string ) bool {
@@ -449,7 +458,7 @@ func (context *EvalContext) evalMarkutFile(loc *Loc, path string, ignoreIfMissin
449458 sb .WriteString ("ERROR: " )
450459 }
451460 sb .WriteString (fmt .Sprintf ("%s" , err ))
452- fmt .Printf ( "%s\n " , sb .String ())
461+ fmt .Fprintf ( os . Stderr , "%s\n " , sb .String ())
453462 return ignoreIfMissing
454463 }
455464
@@ -894,6 +903,7 @@ var Subcommands = map[string]Subcommand{
894903 Run : func (name string , args []string ) bool {
895904 chatFlag := flag .NewFlagSet (name , flag .ContinueOnError )
896905 markutPtr := chatFlag .String ("markut" , "MARKUT" , "Path to the MARKUT file" )
906+ csvPtr := chatFlag .Bool ("csv" , false , "Generate the chat using the stupid Twich Chat Downloader CSV format. You can then feed this output to tools like SubChat https://github.com/Kam1k4dze/SubChat" )
897907
898908 err := chatFlag .Parse (args )
899909
@@ -912,28 +922,40 @@ var Subcommands = map[string]Subcommand{
912922 return false
913923 }
914924
915- capacity := 1
916- ring := []ChatMessage {}
917- timeCursor := Millis (0 )
918- subRipCounter := 0 ;
919- for _ , chunk := range context .chunks {
920- prevTime := chunk .Start
921- for _ , message := range chunk .ChatLog {
922- deltaTime := message .TimeOffset - prevTime
923- prevTime = message .TimeOffset
924- if len (ring ) > 0 {
925- subRipCounter += 1
926- fmt .Printf ("%d\n " , subRipCounter );
927- fmt .Printf ("%s --> %s\n " , millisToSubRipTs (timeCursor ), millisToSubRipTs (timeCursor + deltaTime ));
928- for _ , ringMessage := range ring {
929- fmt .Printf ("%s\n " , ringMessage .Text );
925+ if * csvPtr {
926+ fmt .Printf ("time,user_name,user_color,message\n " );
927+ var cursor Millis = 0
928+ for _ , chunk := range context .chunks {
929+ for _ , message := range chunk .ChatLog {
930+ timestamp := cursor + message .TimeOffset - chunk .Start ;
931+ fmt .Printf ("%d,%s,%s,\" %s\" \n " , timestamp , message .Nickname , message .Color , message .Text_ );
932+ }
933+ cursor += chunk .End - chunk .Start ;
934+ }
935+ } else {
936+ capacity := 1
937+ ring := []ChatMessage {}
938+ timeCursor := Millis (0 )
939+ subRipCounter := 0 ;
940+ for _ , chunk := range context .chunks {
941+ prevTime := chunk .Start
942+ for _ , message := range chunk .ChatLog {
943+ deltaTime := message .TimeOffset - prevTime
944+ prevTime = message .TimeOffset
945+ if len (ring ) > 0 {
946+ subRipCounter += 1
947+ fmt .Printf ("%d\n " , subRipCounter );
948+ fmt .Printf ("%s --> %s\n " , millisToSubRipTs (timeCursor ), millisToSubRipTs (timeCursor + deltaTime ));
949+ for _ , ringMessage := range ring {
950+ fmt .Printf ("[%s] %s\n " , ringMessage .Nickname , ringMessage .Text_ );
951+ }
952+ fmt .Printf ("\n " )
930953 }
931- fmt .Printf ("\n " )
954+ timeCursor += deltaTime
955+ ring = captionsRingPush (ring , message , capacity );
932956 }
933- timeCursor += deltaTime
934- ring = captionsRingPush (ring , message , capacity );
957+ timeCursor += chunk .End - prevTime
935958 }
936- timeCursor += chunk .End - prevTime
937959 }
938960
939961 return true
0 commit comments