Skip to content

Commit 0faf32e

Browse files
committed
Refactor WordCensor to use libse for subtitle handling.
Replaced custom subtitle handling logic with `libse` integration to streamline functionality and improve maintainability. Updated interfaces and method signatures to reflect these changes, while preserving existing behavior and structure. Adjusted project configuration to include the required package reference.
1 parent a7f769b commit 0faf32e

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

source/WordCensor/EntryPoint.cs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Collections.Generic;
22
using System.Windows.Forms;
3+
using Nikse.SubtitleEdit.Core.Common;
4+
using Nikse.SubtitleEdit.Core.SubtitleFormats;
35

46
namespace Nikse.SubtitleEdit.PluginLogic
57
{
@@ -17,10 +19,10 @@ public class WordCensor : IPlugin
1719

1820
public string Shortcut => string.Empty;
1921

20-
public string DoAction(Form parentForm, string subtitle, double frameRate, string listViewLineSeparatorString, string subtitleFileName, string videoFileName, string rawText)
22+
public string DoAction(Form parentForm, string content, double frameRate, string listViewLineSeparatorString, string subtitleFileName, string videoFileName, string rawText)
2123
{
2224
// Make sure subtitle isn't null or empty
23-
if (string.IsNullOrWhiteSpace(subtitle))
25+
if (string.IsNullOrWhiteSpace(content))
2426
{
2527
MessageBox.Show("No subtitle loaded", parentForm.Text,
2628
MessageBoxButtons.OK, MessageBoxIcon.Warning);
@@ -29,25 +31,41 @@ public string DoAction(Form parentForm, string subtitle, double frameRate, strin
2931

3032
// Use custom separator for list view new lines
3133
if (!string.IsNullOrEmpty(listViewLineSeparatorString))
34+
{
3235
Configuration.ListViewLineSeparatorString = listViewLineSeparatorString;
36+
}
3337

34-
// Get subtitle raw lines
35-
var list = new List<string>();
36-
list.AddRange(subtitle.SplitToLines());
37-
38-
var srt = new SubRip();
39-
var sub = new Subtitle(srt);
40-
41-
// Load raws subtitle lines into Subtitle object
42-
srt.LoadSubtitle(sub, list, subtitleFileName);
38+
var subRip = new SubRip();
39+
var subrip = new Subtitle();
40+
subRip.LoadSubtitle(subrip, content.SplitToLines(), subtitleFileName);
41+
if (subrip.Paragraphs.Count < 1)
42+
{
43+
return string.Empty;
44+
}
4345

44-
IPlugin wordCensor = this;
45-
using (var form = new Main(sub, wordCensor.Name, wordCensor.Description))
46+
using (var form = new Main(subrip, Name, Description))
4647
{
4748
if (form.ShowDialog(parentForm) == DialogResult.OK)
49+
{
4850
return form.FixedSubtitle;
51+
}
4952
}
53+
5054
return string.Empty;
5155
}
5256
}
53-
}
57+
58+
/// <summary>
59+
/// Represents a plugin interface for subtitle editing functionality.
60+
/// </summary>
61+
public interface IPlugin
62+
{
63+
string Name { get; }
64+
string Text { get; }
65+
decimal Version { get; }
66+
string Description { get; }
67+
string ActionType { get; }
68+
string Shortcut { get; }
69+
string DoAction(Form parentForm, string content, double frameRate, string listViewLineSeparatorString, string subtitleFileName, string videoFileName, string rawText);
70+
}
71+
}

source/WordCensor/Main.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using System.Linq;
77
using System.Text;
88
using System.Windows.Forms;
9+
using Nikse.SubtitleEdit.Core.Common;
10+
using Nikse.SubtitleEdit.Core.SubtitleFormats;
911

1012
namespace Nikse.SubtitleEdit.PluginLogic
1113
{
@@ -28,7 +30,7 @@ private void buttonCleanup_Click(object sender, EventArgs e)
2830
{
2931
ReloadConfiguration();
3032
_wordHandler.CleanUpSubtitle(_subtitle);
31-
FixedSubtitle = _subtitle.ToText();
33+
FixedSubtitle = _subtitle.ToText(new SubRip());
3234
DialogResult = DialogResult.OK;
3335
}
3436

@@ -39,4 +41,4 @@ private void ReloadConfiguration()
3941

4042
public string FixedSubtitle { get; private set; }
4143
}
42-
}
44+
}

source/WordCensor/WordCensor.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
<UseWindowsForms>true</UseWindowsForms>
66
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
77
</PropertyGroup>
8-
<Import Project="..\Plugin-Shared\Plugin-Shared.projitems" Label="Shared"/>
8+
<ItemGroup>
9+
<PackageReference Include="libse" IncludeAssets="compile"/>
10+
</ItemGroup>
911
</Project>

source/WordCensor/WordsHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Text;
33
using System.Text.RegularExpressions;
4+
using Nikse.SubtitleEdit.Core.Common;
45

56
namespace Nikse.SubtitleEdit.PluginLogic
67
{

source/WordCensor/WordsHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Drawing;
44
using System.Linq;
55
using System.Text;
6+
using Nikse.SubtitleEdit.Core.Common;
67

78
namespace Nikse.SubtitleEdit.PluginLogic
89
{
@@ -104,6 +105,5 @@ public static string ColorWordRed(string word)
104105
string colorString = string.Format("#{0:x2}{1:x2}{2:x2}", c.R, c.G, c.B);
105106
return $"<font color=\"{colorString}\">{word}</font>";
106107
}
107-
108108
}
109-
}
109+
}

0 commit comments

Comments
 (0)