From 5e69ba94ccbb110f8c8b22f6b02895f9a6786418 Mon Sep 17 00:00:00 2001 From: "Martijn van Berkel (Flitskikker)" Date: Sun, 12 Apr 2020 21:28:22 +0200 Subject: [PATCH] Add option to ignore lyrics --- LanguageMaster.xml | 1 + libse/ContinuationUtilities.cs | 13 +++++++++++-- libse/Language.cs | 3 ++- libse/LanguageDeserializer.cs | 3 +++ libse/LanguageStructure.cs | 3 ++- libse/Settings.cs | 10 +++++++++- .../SettingsFixContinuationStyle.Designer.cs | 19 ++++++++++++++++--- src/Forms/SettingsFixContinuationStyle.cs | 3 +++ src/Languages/nl-NL.xml | 1 + src/Test/Logic/ContinuationUtilitiesTest.cs | 1 + 10 files changed, 49 insertions(+), 8 deletions(-) diff --git a/LanguageMaster.xml b/LanguageMaster.xml index 5490f35a4..6e8897dae 100644 --- a/LanguageMaster.xml +++ b/LanguageMaster.xml @@ -2164,6 +2164,7 @@ Continue? Detect and uncheck italic single titles, or lyrics Detect and uncheck single titles, or lyrics, in lowercase Hide unlikely continuation sentences + Ignore lyrics between music symbols Settings for mpv diff --git a/libse/ContinuationUtilities.cs b/libse/ContinuationUtilities.cs index cf20b4c4c..1cbc3783a 100644 --- a/libse/ContinuationUtilities.cs +++ b/libse/ContinuationUtilities.cs @@ -31,6 +31,15 @@ namespace Nikse.SubtitleEdit.Core checkString = Regex.Replace(checkString, "\\(.*?\\)", string.Empty, RegexOptions.Singleline); checkString = Regex.Replace(checkString, "\\[.*?\\]", string.Empty, RegexOptions.Singleline); checkString = Regex.Replace(checkString, "\\{.*?\\}", string.Empty); + + if (Configuration.Settings.General.FixContinuationStyleIgnoreLyrics) + { + foreach (char c in MusicSymbols) + { + checkString = Regex.Replace(checkString, "\\" + c + ".*?\\" + c, string.Empty, RegexOptions.Singleline); + } + } + checkString = checkString.Trim(); // Remove string elevation @@ -102,7 +111,7 @@ namespace Nikse.SubtitleEdit.Core { checkString = checkString.Substring(2).Trim(); } - + // Remove music symbols from the beginning if (checkString.Length > 0 && MusicSymbols.Contains(checkString[0])) { @@ -131,7 +140,7 @@ namespace Nikse.SubtitleEdit.Core { checkString = checkString.Substring(0, checkString.Length - 2).Trim(); } - + // Remove music symbols from the ending if (checkString.Length > 0 && MusicSymbols.Contains(checkString[checkString.Length - 1])) { diff --git a/libse/Language.cs b/libse/Language.cs index f45b54a3b..1bf032f1e 100644 --- a/libse/Language.cs +++ b/libse/Language.cs @@ -2457,7 +2457,8 @@ can edit in same subtitle file (collaboration)", UncheckInsertsAllCaps = "Detect and uncheck single titles in all-caps (for example: NO ENTRY)", UncheckInsertsItalic = "Detect and uncheck italic single titles, or lyrics", UncheckInsertsLowercase = "Detect and uncheck single titles, or lyrics, in lowercase", - HideContinuationCandidatesWithoutName = "Hide unlikely continuation sentences" + HideContinuationCandidatesWithoutName = "Hide unlikely continuation sentences", + IgnoreLyrics = "Ignore lyrics between music symbols" }; SettingsMpv = new LanguageStructure.SettingsMpv diff --git a/libse/LanguageDeserializer.cs b/libse/LanguageDeserializer.cs index d24673a91..b730238c0 100644 --- a/libse/LanguageDeserializer.cs +++ b/libse/LanguageDeserializer.cs @@ -5902,6 +5902,9 @@ namespace Nikse.SubtitleEdit.Core case "Settings/HideContinuationCandidatesWithoutName": language.Settings.HideContinuationCandidatesWithoutName = reader.Value; break; + case "Settings/IgnoreLyrics": + language.Settings.IgnoreLyrics = reader.Value; + break; case "SettingsMpv/Title": language.SettingsMpv.Title = reader.Value; break; diff --git a/libse/LanguageStructure.cs b/libse/LanguageStructure.cs index 2b3525cdd..f42a42278 100644 --- a/libse/LanguageStructure.cs +++ b/libse/LanguageStructure.cs @@ -2325,7 +2325,8 @@ public string UncheckInsertsAllCaps { get; set; } public string UncheckInsertsItalic { get; set; } public string UncheckInsertsLowercase { get; set; } - public string HideContinuationCandidatesWithoutName { get; set; } + public string HideContinuationCandidatesWithoutName { get; set; } + public string IgnoreLyrics { get; set; } } public class SettingsMpv diff --git a/libse/Settings.cs b/libse/Settings.cs index 5a6ba54a3..ef2d714d0 100644 --- a/libse/Settings.cs +++ b/libse/Settings.cs @@ -780,6 +780,7 @@ $HorzAlign = Center public bool FixContinuationStyleUncheckInsertsItalic { get; set; } public bool FixContinuationStyleUncheckInsertsLowercase { get; set; } public bool FixContinuationStyleHideContinuationCandidatesWithoutName { get; set; } + public bool FixContinuationStyleIgnoreLyrics { get; set; } public string SpellCheckLanguage { get; set; } public string VideoPlayer { get; set; } public int VideoPlayerDefaultVolume { get; set; } @@ -926,6 +927,7 @@ $HorzAlign = Center FixContinuationStyleUncheckInsertsItalic = true; FixContinuationStyleUncheckInsertsLowercase = true; FixContinuationStyleHideContinuationCandidatesWithoutName = true; + FixContinuationStyleIgnoreLyrics = true; SpellCheckLanguage = null; VideoPlayer = string.Empty; VideoPlayerDefaultVolume = 75; @@ -2590,7 +2592,13 @@ $HorzAlign = Center { settings.General.FixContinuationStyleHideContinuationCandidatesWithoutName = Convert.ToBoolean(subNode.InnerText, CultureInfo.InvariantCulture); } - + + subNode = node.SelectSingleNode("FixContinuationStyleIgnoreLyrics"); + if (subNode != null) + { + settings.General.FixContinuationStyleIgnoreLyrics = Convert.ToBoolean(subNode.InnerText, CultureInfo.InvariantCulture); + } + subNode = node.SelectSingleNode("SpellCheckLanguage"); if (subNode != null) { diff --git a/src/Forms/SettingsFixContinuationStyle.Designer.cs b/src/Forms/SettingsFixContinuationStyle.Designer.cs index 4195c077f..5cfd2e995 100644 --- a/src/Forms/SettingsFixContinuationStyle.Designer.cs +++ b/src/Forms/SettingsFixContinuationStyle.Designer.cs @@ -34,6 +34,7 @@ this.checkBoxUncheckInsertsItalic = new System.Windows.Forms.CheckBox(); this.checkBoxUncheckInsertsLowercase = new System.Windows.Forms.CheckBox(); this.checkBoxHideContinuationCandidatesWithoutName = new System.Windows.Forms.CheckBox(); + this.checkBoxIgnoreLyrics = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // buttonCancel @@ -41,7 +42,7 @@ 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(351, 128); + this.buttonCancel.Location = new System.Drawing.Point(351, 151); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 10; @@ -53,7 +54,7 @@ // 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(270, 128); + this.buttonOK.Location = new System.Drawing.Point(270, 151); this.buttonOK.Name = "buttonOK"; this.buttonOK.Size = new System.Drawing.Size(75, 23); this.buttonOK.TabIndex = 9; @@ -101,13 +102,24 @@ this.checkBoxHideContinuationCandidatesWithoutName.Text = "Hide interruption continuation candidates that don\'t start with a name"; this.checkBoxHideContinuationCandidatesWithoutName.UseVisualStyleBackColor = true; // + // checkBoxIgnoreLyrics + // + this.checkBoxIgnoreLyrics.AutoSize = true; + this.checkBoxIgnoreLyrics.Location = new System.Drawing.Point(12, 104); + this.checkBoxIgnoreLyrics.Name = "checkBoxIgnoreLyrics"; + this.checkBoxIgnoreLyrics.Size = new System.Drawing.Size(196, 17); + this.checkBoxIgnoreLyrics.TabIndex = 5; + this.checkBoxIgnoreLyrics.Text = "Ignore lyrics between music symbols"; + this.checkBoxIgnoreLyrics.UseVisualStyleBackColor = true; + // // SettingsFixContinuationStyle // this.AcceptButton = this.buttonOK; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.buttonCancel; - this.ClientSize = new System.Drawing.Size(438, 163); + this.ClientSize = new System.Drawing.Size(438, 186); + this.Controls.Add(this.checkBoxIgnoreLyrics); this.Controls.Add(this.checkBoxHideContinuationCandidatesWithoutName); this.Controls.Add(this.checkBoxUncheckInsertsLowercase); this.Controls.Add(this.checkBoxUncheckInsertsItalic); @@ -136,5 +148,6 @@ private System.Windows.Forms.CheckBox checkBoxUncheckInsertsItalic; private System.Windows.Forms.CheckBox checkBoxUncheckInsertsLowercase; private System.Windows.Forms.CheckBox checkBoxHideContinuationCandidatesWithoutName; + private System.Windows.Forms.CheckBox checkBoxIgnoreLyrics; } } \ No newline at end of file diff --git a/src/Forms/SettingsFixContinuationStyle.cs b/src/Forms/SettingsFixContinuationStyle.cs index 1f7ef2348..f16d8b471 100644 --- a/src/Forms/SettingsFixContinuationStyle.cs +++ b/src/Forms/SettingsFixContinuationStyle.cs @@ -26,11 +26,13 @@ namespace Nikse.SubtitleEdit.Forms checkBoxUncheckInsertsItalic.Text = language.UncheckInsertsItalic; checkBoxUncheckInsertsLowercase.Text = language.UncheckInsertsLowercase; checkBoxHideContinuationCandidatesWithoutName.Text = language.HideContinuationCandidatesWithoutName; + checkBoxIgnoreLyrics.Text = language.IgnoreLyrics; checkBoxUncheckInsertsAllCaps.Checked = settings.FixContinuationStyleUncheckInsertsAllCaps; checkBoxUncheckInsertsItalic.Checked = settings.FixContinuationStyleUncheckInsertsItalic; checkBoxUncheckInsertsLowercase.Checked = settings.FixContinuationStyleUncheckInsertsLowercase; checkBoxHideContinuationCandidatesWithoutName.Checked = settings.FixContinuationStyleHideContinuationCandidatesWithoutName; + checkBoxIgnoreLyrics.Checked = settings.FixContinuationStyleIgnoreLyrics; buttonOK.Text = Configuration.Settings.Language.General.Ok; buttonCancel.Text = Configuration.Settings.Language.General.Cancel; @@ -43,6 +45,7 @@ namespace Nikse.SubtitleEdit.Forms Configuration.Settings.General.FixContinuationStyleUncheckInsertsItalic = checkBoxUncheckInsertsItalic.Checked; Configuration.Settings.General.FixContinuationStyleUncheckInsertsLowercase = checkBoxUncheckInsertsLowercase.Checked; Configuration.Settings.General.FixContinuationStyleHideContinuationCandidatesWithoutName = checkBoxHideContinuationCandidatesWithoutName.Checked; + Configuration.Settings.General.FixContinuationStyleIgnoreLyrics = checkBoxIgnoreLyrics.Checked; DialogResult = DialogResult.OK; } diff --git a/src/Languages/nl-NL.xml b/src/Languages/nl-NL.xml index 539a67613..8509bad28 100644 --- a/src/Languages/nl-NL.xml +++ b/src/Languages/nl-NL.xml @@ -2165,6 +2165,7 @@ of tijdens het exporteren naar op beeld gebaseerde formaten. Cursieve beeldtitels of songteksten detecteren en uitvinken Beeldtitels of songteksten in kleine letters detecteren en uitvinken Onwaarschijnlijke vervolgzinnen verbergen + Songteksten tussen muzieksymbolen negeren mpv instellingen diff --git a/src/Test/Logic/ContinuationUtilitiesTest.cs b/src/Test/Logic/ContinuationUtilitiesTest.cs index 314d355ed..d3d3b7aa8 100644 --- a/src/Test/Logic/ContinuationUtilitiesTest.cs +++ b/src/Test/Logic/ContinuationUtilitiesTest.cs @@ -121,6 +121,7 @@ namespace Test.Logic public void SanitizeString11() { string line1 = "♪ la la la ♪"; + Configuration.Settings.General.FixContinuationStyleIgnoreLyrics = false; string line1Actual = ContinuationUtilities.SanitizeString(line1, false); string line1Expected = "la la la"; Assert.AreEqual(line1Expected, line1Actual);