Add new settings for webvtt auto merge

This commit is contained in:
niksedk 2023-04-25 18:40:20 +02:00
parent 4ceccc82a7
commit f6a239df5c
5 changed files with 38 additions and 8 deletions

View File

@ -765,6 +765,7 @@ namespace Nikse.SubtitleEdit.Core.Common
public bool WebVttUseXTimestampMap { get; set; }
public bool WebVttUseMultipleXTimestampMap { get; set; }
public bool WebVttMergeLinesWithSameText { get; set; }
public long WebVttTimescale { get; set; }
public string WebVttCueAn1 { get; set; }
public string WebVttCueAn2 { get; set; }
@ -6940,6 +6941,12 @@ $HorzAlign = Center
{
settings.SubtitleSettings.WebVttUseMultipleXTimestampMap = Convert.ToBoolean(subNode.InnerText, CultureInfo.InvariantCulture);
}
subNode = node.SelectSingleNode("WebVttMergeLinesWithSameText");
if (subNode != null)
{
settings.SubtitleSettings.WebVttMergeLinesWithSameText = Convert.ToBoolean(subNode.InnerText, CultureInfo.InvariantCulture);
}
}
// Proxy
@ -10898,6 +10905,7 @@ $HorzAlign = Center
textWriter.WriteElementString("BluRaySupForceMergeAll", settings.SubtitleSettings.BluRaySupForceMergeAll.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("WebVttUseXTimestampMap", settings.SubtitleSettings.WebVttUseXTimestampMap.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("WebVttUseMultipleXTimestampMap", settings.SubtitleSettings.WebVttUseMultipleXTimestampMap.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("WebVttMergeLinesWithSameText", settings.SubtitleSettings.WebVttMergeLinesWithSameText.ToString(CultureInfo.InvariantCulture));
textWriter.WriteEndElement();
textWriter.WriteStartElement("Proxy", string.Empty);

View File

@ -357,9 +357,14 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
paragraph.Text = RemoveWeirdRepeatingHeader(paragraph.Text);
}
var merged = MergeLinesSameTextUtils.MergeLinesWithSameTextInSubtitle(subtitle, false, 1);
subtitle.Paragraphs.Clear();
subtitle.Paragraphs.AddRange(merged.Paragraphs);
if (Configuration.Settings.SubtitleSettings.WebVttMergeLinesWithSameText)
{
var merged = MergeLinesSameTextUtils.MergeLinesWithSameTextInSubtitle(subtitle, false, 1);
subtitle.Paragraphs.Clear();
subtitle.Paragraphs.AddRange(merged.Paragraphs);
}
subtitle.Renumber();
if (header.Length > 0)
{

View File

@ -52,6 +52,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
sb.AppendLine(string.Format(paragraphWriteFormat, start, end, positionInfo, WebVTT.FormatText(p), style, Environment.NewLine));
count++;
}
return sb.ToString().Trim();
}

View File

@ -51,6 +51,7 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
this.textBoxAn7 = new System.Windows.Forms.TextBox();
this.labelAn7 = new System.Windows.Forms.Label();
this.checkBoxUseXTimestampMap = new System.Windows.Forms.CheckBox();
this.checkBoxAutoMerge = new System.Windows.Forms.CheckBox();
this.groupBoxAlignment.SuspendLayout();
this.SuspendLayout();
//
@ -59,7 +60,7 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonCancel.Location = new System.Drawing.Point(465, 310);
this.buttonCancel.Location = new System.Drawing.Point(465, 317);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 23;
@ -71,7 +72,7 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.buttonOK.Location = new System.Drawing.Point(384, 310);
this.buttonOK.Location = new System.Drawing.Point(384, 317);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 22;
@ -104,7 +105,7 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
this.groupBoxAlignment.Controls.Add(this.labelAn7);
this.groupBoxAlignment.Location = new System.Drawing.Point(12, 22);
this.groupBoxAlignment.Name = "groupBoxAlignment";
this.groupBoxAlignment.Size = new System.Drawing.Size(528, 248);
this.groupBoxAlignment.Size = new System.Drawing.Size(528, 255);
this.groupBoxAlignment.TabIndex = 24;
this.groupBoxAlignment.TabStop = false;
this.groupBoxAlignment.Text = "Alignment";
@ -257,18 +258,30 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
//
this.checkBoxUseXTimestampMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.checkBoxUseXTimestampMap.AutoSize = true;
this.checkBoxUseXTimestampMap.Location = new System.Drawing.Point(12, 292);
this.checkBoxUseXTimestampMap.Location = new System.Drawing.Point(12, 274);
this.checkBoxUseXTimestampMap.Name = "checkBoxUseXTimestampMap";
this.checkBoxUseXTimestampMap.Size = new System.Drawing.Size(212, 17);
this.checkBoxUseXTimestampMap.TabIndex = 25;
this.checkBoxUseXTimestampMap.Text = "Use X-TIMESTAMP-MAP header value";
this.checkBoxUseXTimestampMap.UseVisualStyleBackColor = true;
//
// checkBoxAutoMerge
//
this.checkBoxAutoMerge.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.checkBoxAutoMerge.AutoSize = true;
this.checkBoxAutoMerge.Location = new System.Drawing.Point(12, 297);
this.checkBoxAutoMerge.Name = "checkBoxAutoMerge";
this.checkBoxAutoMerge.Size = new System.Drawing.Size(188, 17);
this.checkBoxAutoMerge.TabIndex = 26;
this.checkBoxAutoMerge.Text = "Merge lines with same text on load";
this.checkBoxAutoMerge.UseVisualStyleBackColor = true;
//
// WebVttProperties
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(552, 345);
this.ClientSize = new System.Drawing.Size(552, 352);
this.Controls.Add(this.checkBoxAutoMerge);
this.Controls.Add(this.checkBoxUseXTimestampMap);
this.Controls.Add(this.groupBoxAlignment);
this.Controls.Add(this.buttonCancel);
@ -314,5 +327,6 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
private System.Windows.Forms.TextBox textBoxAn7;
private System.Windows.Forms.Label labelAn7;
private System.Windows.Forms.CheckBox checkBoxUseXTimestampMap;
private System.Windows.Forms.CheckBox checkBoxAutoMerge;
}
}

View File

@ -39,6 +39,7 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
textBoxAn9.Text = Configuration.Settings.SubtitleSettings.WebVttCueAn9;
checkBoxUseXTimestampMap.Checked = Configuration.Settings.SubtitleSettings.WebVttUseXTimestampMap;
checkBoxAutoMerge.Checked = Configuration.Settings.SubtitleSettings.WebVttMergeLinesWithSameText;
}
private void buttonOK_Click(object sender, EventArgs e)
@ -54,6 +55,7 @@ namespace Nikse.SubtitleEdit.Forms.FormatProperties
Configuration.Settings.SubtitleSettings.WebVttCueAn9 = textBoxAn9.Text;
Configuration.Settings.SubtitleSettings.WebVttUseXTimestampMap = checkBoxUseXTimestampMap.Checked;
Configuration.Settings.SubtitleSettings.WebVttMergeLinesWithSameText = checkBoxAutoMerge.Checked;
DialogResult = DialogResult.OK;
}