Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
New chat download simple text options
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Apr 12, 2021
1 parent 77123c0 commit 11264c9
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 7 deletions.
3 changes: 3 additions & 0 deletions TwitchDownloaderCLI/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using TwitchDownloaderCore.Options;

namespace TwitchDownloaderCLI
{
Expand Down Expand Up @@ -35,6 +36,8 @@ class Options
public string Oauth { get; set; }
[Option("timestamp", HelpText = "Enable timestamp for chat download in .txt format or chat render.")]
public bool Timestamp { get; set; }
[Option("timestamp-format", HelpText = "Sets the timestamp format for .txt chat logs. Valid values are Utc, Relative, and None")]
public TimestampFormat TimeFormat { get; set; }
[Option("embed-emotes", HelpText = "Embed emotes into chat download.")]
public bool EmbedEmotes { get; set; }
[Option("background-color", Default = "#111111", HelpText = "Color of background for chat render.")]
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ private static void DownloadChat(Options inputOptions)
downloadOptions.Timestamp = inputOptions.Timestamp;
downloadOptions.EmbedEmotes = inputOptions.EmbedEmotes;
downloadOptions.Filename = inputOptions.OutputFile;
downloadOptions.TimeFormat = inputOptions.TimeFormat;

ChatDownloader chatDownloader = new ChatDownloader(downloadOptions);
Progress<ProgressReport> progress = new Progress<ProgressReport>();
Expand Down
3 changes: 3 additions & 0 deletions TwitchDownloaderCLI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ Time in seconds to crop ending. For example if I wanted a 10 second stream but o
**-\-timestamp**
If downloading to a text file, will add timestamps before each message.

**-\-timestamp-format**
Sets the timestamp format for .txt chat logs. Valid values are Utc, Relative, and None.

**-\-embed-emotes**
Embeds emotes into the JSON file so in the future when an emote is removed from Twitch or a 3rd party, it will still render correctly. Useful for archival purposes, file size will be larger.
## Arguments for mode ChatRender
Expand Down
17 changes: 15 additions & 2 deletions TwitchDownloaderCore/ChatDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,21 @@ await Task.Run(() => {
string message = comment.message.body;
if (downloadOptions.Timestamp)
{
string timestamp = comment.created_at.ToString("u").Replace("Z", " UTC");
sw.WriteLine(String.Format("[{0}] {1}: {2}", timestamp, username, message));
if (downloadOptions.TimeFormat == TimestampFormat.Utc)
{
string timestamp = comment.created_at.ToString("u").Replace("Z", " UTC");
sw.WriteLine(String.Format("[{0}] {1}: {2}", timestamp, username, message));
}
else if (downloadOptions.TimeFormat == TimestampFormat.Relative)
{
TimeSpan time = new TimeSpan(0, 0, (int)comment.content_offset_seconds);
string timestamp = time.ToString(@"h\:mm\:ss");
sw.WriteLine(String.Format("[{0}] {1}: {2}", timestamp, username, message));
}
else if (downloadOptions.TimeFormat == TimestampFormat.None)
{
sw.WriteLine(String.Format("{0}: {1}", username, message));
}
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions TwitchDownloaderCore/Options/ChatDownloadOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace TwitchDownloaderCore.Options
{
public enum TimestampFormat { Utc, Relative, None }
public class ChatDownloadOptions
{
public bool IsJson { get; set; } = true;
Expand All @@ -15,5 +16,6 @@ public class ChatDownloadOptions
public double CropEndingTime { get; set; }
public bool Timestamp { get; set; }
public bool EmbedEmotes { get; set; }
public TimestampFormat TimeFormat { get; set; }
}
}
4 changes: 2 additions & 2 deletions TwitchDownloaderCore/TwitchDownloaderCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RepositoryUrl>https://github.com/lay295/TwitchDownloader</RepositoryUrl>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Authors>Lewis Pardo</Authors>
<Version>1.0.7</Version>
<Version>1.0.9</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion TwitchDownloaderWPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using AutoUpdaterDotNET;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
Expand Down Expand Up @@ -72,6 +73,8 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)
Settings.Default.Save();
if (!File.Exists("ffmpeg.exe"))
await FFmpegDownloader.GetLatestVersion(FFmpegVersion.Full);

AutoUpdater.Start("https://downloader-update.twitcharchives.workers.dev");
}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
Expand Down
8 changes: 7 additions & 1 deletion TwitchDownloaderWPF/PageChatDownload.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,19 @@
<StackPanel Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2" Margin="0,20,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
<StackPanel HorizontalAlignment="Left">
<TextBlock Text="Download Format:" HorizontalAlignment="Right" Margin="0,10,0,0"/>
<TextBlock Visibility="Collapsed" x:Name="timeText" Text="Timestamp Format:" HorizontalAlignment="Right" Margin="0,10,0,0"/>
<TextBlock Text="Crop Chat:" HorizontalAlignment="Right" Margin="0,10,0,0"/>
<TextBlock HorizontalAlignment="Right" Margin="0,29,0,0">Embed Emotes <Hyperlink ToolTipService.ShowDuration="30000"><Hyperlink.ToolTip>Embeds emotes into the JSON file so in the future when an emote is removed from Twitch or a 3rd party, it will still render correctly. Useful for archival purposes, file size will be larger.</Hyperlink.ToolTip>(?)</Hyperlink>:</TextBlock>
</StackPanel>
<StackPanel>
<StackPanel Margin="5,12,0,0" Orientation="Horizontal">
<RadioButton x:Name="radioJson" IsChecked="True" Content="Advanced JSON"/>
<RadioButton x:Name="radioText" Content="Simple Text" Margin="3,0,0,0"/>
<RadioButton x:Name="radioText" Content="Simple Text" Margin="3,0,0,0" Checked="radioText_Checked" Unchecked="radioText_Unchecked"/>
</StackPanel>
<StackPanel Visibility="Collapsed" x:Name="timeOptions" Margin="5,8,0,0" Orientation="Horizontal">
<RadioButton x:Name="radioUTC" IsChecked="True" Content="UTC"/>
<RadioButton x:Name="radioRelative" Content="Relative" Margin="3,0,0,0"/>
<RadioButton x:Name="radioNone" Content="None" Margin="3,0,0,0"/>
</StackPanel>
<StackPanel Margin="5,5,0,0">
<StackPanel Orientation="Horizontal">
Expand Down
25 changes: 25 additions & 0 deletions TwitchDownloaderWPF/PageChatDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ private void SetEnabled(bool isEnabled, bool onlyCrop)
numEndHour.IsEnabled = isEnabled;
numEndMinute.IsEnabled = isEnabled;
numEndSecond.IsEnabled = isEnabled;
checkEmbed.IsEnabled = isEnabled;
radioRelative.IsEnabled = isEnabled;
radioUTC.IsEnabled = isEnabled;
radioNone.IsEnabled = isEnabled;

if (!onlyCrop)
{
Expand Down Expand Up @@ -227,6 +231,13 @@ private async void btnDownload_Click(object sender, RoutedEventArgs e)
downloadOptions.Id = downloadId;
}

if ((bool)radioUTC.IsChecked)
downloadOptions.TimeFormat = TimestampFormat.Utc;
if ((bool)radioRelative.IsChecked)
downloadOptions.TimeFormat = TimestampFormat.Relative;
if ((bool)radioNone.IsChecked)
downloadOptions.TimeFormat = TimestampFormat.None;

ChatDownloader currentDownload = new ChatDownloader(downloadOptions);

btnGetInfo.IsEnabled = false;
Expand Down Expand Up @@ -299,6 +310,20 @@ private void btnSettings_Loaded(object sender, RoutedEventArgs e)
{
btnDonate.Visibility = Settings.Default.HideDonation ? Visibility.Collapsed : Visibility.Visible;
}

private void radioText_Checked(object sender, RoutedEventArgs e)
{
timeText.Visibility = Visibility.Visible;
timeOptions.Visibility = Visibility.Visible;
checkEmbed.IsEnabled = false;
}

private void radioText_Unchecked(object sender, RoutedEventArgs e)
{
timeText.Visibility = Visibility.Collapsed;
timeOptions.Visibility = Visibility.Collapsed;
checkEmbed.IsEnabled = true;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderWPF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.39.5.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
4 changes: 4 additions & 0 deletions TwitchDownloaderWPF/TwitchDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoUpdater.NET, Version=1.6.4.0, Culture=neutral, PublicKeyToken=501435c91b35f4bc, processorArchitecture=MSIL">
<HintPath>..\packages\Autoupdater.NET.Official.1.6.4\lib\net45\AutoUpdater.NET.dll</HintPath>
</Reference>
<Reference Include="Emoji.Wpf, Version=0.0.0.19, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Emoji.Wpf.0.0.19-experimental\lib\net30\Emoji.Wpf.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -130,6 +133,7 @@
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
<Reference Include="System.Threading.Thread" />
<Reference Include="System.Windows.Controls.Input.Toolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderWPF/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autoupdater.NET.Official" version="1.6.4" targetFramework="net472" />
<package id="Emoji.Wpf" version="0.0.19-experimental" targetFramework="net472" />
<package id="Extended.Wpf.Toolkit" version="3.6.0" targetFramework="net472" />
<package id="Infragistics.Themes.IG.Wpf" version="1.0.0" targetFramework="net472" />
Expand Down

0 comments on commit 11264c9

Please sign in to comment.