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

Commit

Permalink
Add sub messages
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Dec 21, 2020
1 parent 1932294 commit 7455155
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 11 deletions.
29 changes: 23 additions & 6 deletions TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ await Task.Run(() =>
continue;
if (comment.message.user_notice_params != null && comment.message.user_notice_params.msg_id != null)
{
if (comment.message.user_notice_params.msg_id != "highlighted-message" && comment.message.user_notice_params.msg_id != "")
if (comment.message.user_notice_params.msg_id != "highlighted-message" && comment.message.user_notice_params.msg_id != "sub" && comment.message.user_notice_params.msg_id != "resub" && comment.message.user_notice_params.msg_id != "subgift" && comment.message.user_notice_params.msg_id != "")
continue;
if (!renderOptions.SubMessages && (comment.message.user_notice_params.msg_id == "sub" || comment.message.user_notice_params.msg_id == "resub" || comment.message.user_notice_params.msg_id == "subgift"))
continue;
}

Expand All @@ -88,17 +90,28 @@ await Task.Run(() =>
List<SKBitmap> imageList = new List<SKBitmap>();
SKBitmap sectionImage = new SKBitmap(canvasSize.Width, canvasSize.Height);
int default_x = renderOptions.PaddingLeft;
bool accentMessage = false;

List<GifEmote> currentGifEmotes = new List<GifEmote>();
List<SKBitmap> emoteList = new List<SKBitmap>();
List<SKRect> emotePositionList = new List<SKRect>();
new SKCanvas(sectionImage).Clear(renderOptions.BackgroundColor);

if (renderOptions.Timestamp)
sectionImage = DrawTimestamp(sectionImage, imageList, messageFont, renderOptions, comment, canvasSize, ref drawPos, ref default_x);
sectionImage = DrawBadges(sectionImage, imageList, renderOptions, chatBadges, comment, canvasSize, ref drawPos);
sectionImage = DrawUsername(sectionImage, imageList, renderOptions, nameFont, comment.commenter.display_name, userColor, canvasSize, ref drawPos);
sectionImage = DrawMessage(sectionImage, imageList, renderOptions, currentGifEmotes, messageFont, emojiCache, chatEmotes, thirdPartyEmotes, cheerEmotes, comment, canvasSize, ref drawPos, ref default_x, emoteList, emotePositionList);
if (comment.message.user_notice_params != null && comment.message.user_notice_params.msg_id != null && (comment.message.user_notice_params.msg_id == "sub" || comment.message.user_notice_params.msg_id == "resub" || comment.message.user_notice_params.msg_id == "subgift"))
{
accentMessage = true;
drawPos.X += (int)(8 * renderOptions.EmoteScale);
default_x += (int)(8 * renderOptions.EmoteScale);
sectionImage = DrawMessage(sectionImage, imageList, renderOptions, currentGifEmotes, messageFont, emojiCache, chatEmotes, thirdPartyEmotes, cheerEmotes, comment, canvasSize, ref drawPos, ref default_x, emoteList, emotePositionList);
}
else
{
if (renderOptions.Timestamp)
sectionImage = DrawTimestamp(sectionImage, imageList, messageFont, renderOptions, comment, canvasSize, ref drawPos, ref default_x);
sectionImage = DrawBadges(sectionImage, imageList, renderOptions, chatBadges, comment, canvasSize, ref drawPos);
sectionImage = DrawUsername(sectionImage, imageList, renderOptions, nameFont, comment.commenter.display_name, userColor, canvasSize, ref drawPos);
sectionImage = DrawMessage(sectionImage, imageList, renderOptions, currentGifEmotes, messageFont, emojiCache, chatEmotes, thirdPartyEmotes, cheerEmotes, comment, canvasSize, ref drawPos, ref default_x, emoteList, emotePositionList);
}

int finalHeight = 0;
foreach (var img in imageList)
Expand All @@ -114,6 +127,9 @@ await Task.Run(() =>
img.Dispose();
}

if (accentMessage)
finalImageCanvas.DrawRect(renderOptions.PaddingLeft, 0, (int)(4 * renderOptions.EmoteScale), finalHeight - (int)Math.Floor(.4 * renderOptions.SectionHeight), new SKPaint() { Color = SKColor.Parse("#7b2cf2") });

string imagePath = Path.Combine(downloadFolder, Guid.NewGuid() + ".png");
finalComments.Add(new TwitchComment() { Section = imagePath, SecondsOffset = Double.Parse(comment.content_offset_seconds.ToString()), GifEmotes = currentGifEmotes, NormalEmotes = emoteList, NormalEmotesPositions = emotePositionList });
using (Stream s = File.OpenWrite(imagePath))
Expand All @@ -127,6 +143,7 @@ await Task.Run(() =>
}
finalImage.Dispose();
finalImageCanvas.Dispose();

int percent = (int)Math.Floor(((double)finalComments.Count / (double)chatJson.comments.Count) * 100);
CheckCancelation(cancellationToken, downloadFolder);
}
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderCore/Options/ChatRenderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ public string OutputFileMask
public string OutputArgs { get; set; }
public string FfmpegPath { get; set; }
public string TempFolder { get; set; }
public bool SubMessages { get; set; }
}
}
3 changes: 3 additions & 0 deletions TwitchDownloaderWPF/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
<setting name="TemplateChat" serializeAs="String">
<value>[{date_custom="M-d-yy"}] {channel} - {title}</value>
</setting>
<setting name="SubMessages" serializeAs="String">
<value>True</value>
</setting>
</TwitchDownloader.Properties.Settings>
</userSettings>
</configuration>
8 changes: 5 additions & 3 deletions TwitchDownloaderWPF/PageChatRender.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<TextBlock Text="Font:" HorizontalAlignment="Right" Margin="0,2,0,0"/>
<TextBlock Text="Font Size:" HorizontalAlignment="Right" Margin="0,14,0,0"/>
<TextBlock Text="Font Color:" HorizontalAlignment="Right" Margin="0,14,0,0"/>
<TextBlock Text="Outline:" HorizontalAlignment="Right" Margin="0,8,0,0"/>
<TextBlock Text="Outline:" HorizontalAlignment="Right" Margin="0,9,0,0"/>
<TextBlock Text="Timestamp:" HorizontalAlignment="Right" Margin="0,6,0,0"/>
<TextBlock Text="FFZ Emotes:" HorizontalAlignment="Right" Margin="0,6,0,0"/>
<TextBlock Text="BTTV Emotes:" HorizontalAlignment="Right" Margin="0,6,0,0"/>
Expand All @@ -44,22 +44,24 @@
<xctk:ColorPicker x:Name="colorFont" SelectedColor="#111111" Width="50" UsingAlphaChannel="False" Margin="0,5,0,0" HorizontalAlignment="Left" DropDownBackground="{StaticResource ResourceKey=FixBrush}" SelectedColorChanged="UpdateColor"/>
<CheckBox x:Name="checkOutline" Margin="0,6,0,0" Checked="UpdateCheckbox" Unchecked="UpdateCheckbox"/>
<CheckBox x:Name="checkTimestamp" Margin="0,6,0,0" Checked="UpdateCheckbox" Unchecked="UpdateCheckbox"/>
<CheckBox x:Name="checkFFZ" IsChecked="True" Margin="0,5,0,0"/>
<CheckBox x:Name="checkBTTV" IsChecked="True" Margin="0,5,0,0"/>
<CheckBox x:Name="checkFFZ" IsChecked="True" Margin="0,6,0,0"/>
<CheckBox x:Name="checkBTTV" IsChecked="True" Margin="0,6,0,0"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="20,0,5,0">
<TextBlock Text="Background Color:" HorizontalAlignment="Right"/>
<TextBlock Text="Height:" HorizontalAlignment="Right" Margin="0,13,0,0"/>
<TextBlock Text="Width:" HorizontalAlignment="Right" Margin="0,13,0,0"/>
<TextBlock Text="Update Time:" HorizontalAlignment="Right" Margin="0,13,0,0"/>
<TextBlock Text="Framerate:" HorizontalAlignment="Right" Margin="0,13,0,0"/>
<TextBlock Text="Sub Messages:" HorizontalAlignment="Right" Margin="0,11,0,0"/>
</StackPanel>
<StackPanel Orientation="Vertical">
<xctk:ColorPicker x:Name="colorBackground" SelectedColor="#111111" Width="50" DropDownBackground="{StaticResource ResourceKey=FixBrush}" SelectedColorChanged="UpdateColor"/>
<TextBox x:Name="textHeight" Text="600" Margin="0,5,0,0" TextChanged="UpdatePreview"/>
<TextBox x:Name="textWidth" Text="350" Margin="0,5,0,0" TextChanged="UpdatePreview"/>
<TextBox x:Name="textUpdateTime" Text="1.0" Margin="0,5,0,0"/>
<TextBox x:Name="textFramerate" Text="60" Margin="0,5,0,0"/>
<CheckBox x:Name="checkSub" IsChecked="True" Margin="0,6,0,0"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="20,0,5,0">
<TextBlock Text="Live Preview:" HorizontalAlignment="Right" Margin="0,6,0,0"/>
Expand Down
7 changes: 5 additions & 2 deletions TwitchDownloaderWPF/PageChatRender.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private async void btnRender_Click(object sender, RoutedEventArgs e)
SKColor messageColor = new SKColor(colorFont.SelectedColor.Value.R, colorFont.SelectedColor.Value.G, colorFont.SelectedColor.Value.B);
SaveSettings();

ChatRenderOptions options = new ChatRenderOptions() {
ChatRenderOptions options = new ChatRenderOptions() {
InputFile = textJson.Text,
OutputFile = saveFileDialog.FileName,
BackgroundColor = backgroundColor,
Expand All @@ -94,7 +94,8 @@ private async void btnRender_Click(object sender, RoutedEventArgs e)
GenerateMask = (bool)checkMask.IsChecked,
OutlineSize = 4,
FfmpegPath = "ffmpeg",
TempFolder = Settings.Default.TempPath
TempFolder = Settings.Default.TempPath,
SubMessages = (bool)checkSub.IsChecked
};
options.PaddingLeft = (int)Math.Floor(2 * options.EmoteScale);

Expand Down Expand Up @@ -153,6 +154,7 @@ private void LoadSettings()
colorFont.SelectedColor = System.Windows.Media.Color.FromRgb((byte)Settings.Default.FontColorR, (byte)Settings.Default.FontColorG, (byte)Settings.Default.FontColorB);
textFramerate.Text = Settings.Default.Framerate.ToString();
checkMask.IsChecked = Settings.Default.GenerateMask;
checkSub.IsChecked = Settings.Default.SubMessages;

foreach (VideoContainer container in comboFormat.Items)
{
Expand Down Expand Up @@ -221,6 +223,7 @@ private void SaveSettings()
Settings.Default.FontColorG = colorFont.SelectedColor.Value.G;
Settings.Default.FontColorB = colorFont.SelectedColor.Value.B;
Settings.Default.GenerateMask = (bool)checkMask.IsChecked;
Settings.Default.SubMessages = (bool)checkSub.IsChecked;
if (comboFormat.SelectedItem != null)
Settings.Default.VideoContainer = ((VideoContainer)comboFormat.SelectedItem).Name;
if (comboCodec.SelectedItem != null)
Expand Down
12 changes: 12 additions & 0 deletions TwitchDownloaderWPF/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions TwitchDownloaderWPF/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,8 @@
<Setting Name="TemplateChat" Type="System.String" Scope="User">
<Value Profile="(Default)">[{date_custom="M-d-yy"}] {channel} - {title}</Value>
</Setting>
<Setting Name="SubMessages" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
2 changes: 2 additions & 0 deletions TwitchDownloaderWPF/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
</StackPanel>
<TextBlock Margin="3,5,3,3">
Avaliable paramaters are: <Bold>{title} {id} {date} {channel} {date_custom=""}</Bold>
<LineBreak/>
Date custom formatting is based on the C# <Hyperlink NavigateUri="https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings" RequestNavigate="Hyperlink_RequestNavigate">standard date and time format strings</Hyperlink>
</TextBlock>
</StackPanel>

Expand Down
7 changes: 7 additions & 0 deletions TwitchDownloaderWPF/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -87,5 +88,11 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
Settings.Default.HideDonation = (bool)checkDonation.IsChecked;
Settings.Default.Save();
}

private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
{
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
}
}

0 comments on commit 7455155

Please sign in to comment.