Skip to content

Commit

Permalink
Add support to milliseconds information in timestamp (#758)
Browse files Browse the repository at this point in the history
* Add support to extract chat timestamps with milliseconds information (txt file only)

* Change from UtcMilliseconds to UtcFull.
Add option information to ChatDownloadArgs.cs

* Add new option to README.md
  • Loading branch information
jmSfernandes authored Jul 18, 2023
1 parent 1a32216 commit c9d2630
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion TwitchDownloaderCLI/Modes/Arguments/ChatDownloadArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ChatDownloadArgs
[Option("stv", Default = true, HelpText = "Enable 7TV embedding in chat download. Requires -E / --embed-images!")]
public bool? StvEmotes { get; set; }

[Option("timestamp-format", Default = TimestampFormat.Relative, HelpText = "Sets the timestamp format for .txt chat logs. Valid values are: Utc, Relative, and None")]
[Option("timestamp-format", Default = TimestampFormat.Relative, HelpText = "Sets the timestamp format for .txt chat logs. Valid values are: Utc, UtcFull, Relative, and None")]
public TimestampFormat TimeFormat { get; set; }

[Option("chat-connections", Default = 4, HelpText = "Number of downloading connections for chat")]
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderCLI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Time in seconds to crop ending. For example if I had a 10 second stream but only
(Default: `true`) 7TV emote embedding. Requires `-E / --embed-images`.

**--timestamp-format**
(Default: `Relative`) Sets the timestamp format for .txt chat logs. Valid values are: `Utc`, `Relative`, and `None`.
(Default: `Relative`) Sets the timestamp format for .txt chat logs. Valid values are: `Utc`, `UtcFull`, `Relative`, and `None`.

**--chat-connections**
(Default: `4`) The number of parallel downloads for chat.
Expand Down
7 changes: 6 additions & 1 deletion TwitchDownloaderCore/Chat/ChatText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public static async Task SerializeAsync(string filePath, ChatRoot chatRoot, Time
string message = comment.message.body;
if (timeFormat == TimestampFormat.Utc)
{
string timestamp = comment.created_at.ToString("u").Replace("Z", " UTC");
var timestamp = comment.created_at.ToString("yyyy'-'MM'-'dd HH':'mm':'ss 'UTC'");;
await sw.WriteLineAsync($"[{timestamp}] {username}: {message}");
}
else if (timeFormat == TimestampFormat.UtcFull)
{
var timestamp = comment.created_at.ToString("yyyy'-'MM'-'dd HH':'mm':'ss.fff 'UTC'");;
await sw.WriteLineAsync($"[{timestamp}] {username}: {message}");
}
else if (timeFormat == TimestampFormat.Relative)
Expand Down
3 changes: 2 additions & 1 deletion TwitchDownloaderCore/Chat/TimestampFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum TimestampFormat
{
Utc,
Relative,
None
None,
UtcFull
}
}

0 comments on commit c9d2630

Please sign in to comment.