Permalink
Browse files

Minor improvements for Netflix dialogs regarding space after hyphen

  • Loading branch information...
niksedk committed May 7, 2017
1 parent 1f80df9 commit 2701b5a7437e8191a36865d0f23f45aa47a3ac49
View
@@ -183,7 +183,7 @@
<Compile Include="NetflixQualityCheck\NetflixCheckGlyph.cs" />
<Compile Include="NetflixQualityCheck\INetflixQualityChecker.cs" />
<Compile Include="NetflixQualityCheck\NetflixCheckTextForHiUseBrackets.cs" />
<Compile Include="NetflixQualityCheck\NetflixCheckDialogeHyphenNoSpace.cs" />
<Compile Include="NetflixQualityCheck\NetflixCheckDialogeHyphenSpace.cs" />
<Compile Include="NetflixQualityCheck\NetflixCheckMaxCps.cs" />
<Compile Include="NetflixQualityCheck\NetflixCheckTwoFramesGap.cs" />
<Compile Include="NetflixQualityCheck\NetflixCheckNumberOfLines.cs" />

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,108 @@
using Nikse.SubtitleEdit.Core.Forms.FixCommonErrors;
using System;
namespace Nikse.SubtitleEdit.Core.NetflixQualityCheck
{
public class NetflixCheckDialogeHyphenSpace : INetflixQualityChecker
{
/// <summary>
/// Use a hyphen with or without a space to indicate two speakers in one subtitle
/// </summary>
public void Check(Subtitle subtitle, NetflixQualityController controller)
{
if (controller.DualSpeakersHasHypenAndNoSplace)
{
RemoveSpaceAfterHyphenInDialogues(subtitle, controller);
}
else
{
AddSpaceAfterHyphenInDialogues(subtitle, controller);
}
}
private static void RemoveSpaceAfterHyphenInDialogues(Subtitle subtitle, NetflixQualityController controller)
{
foreach (Paragraph p in subtitle.Paragraphs)
{
var arr = p.Text.SplitToLines();
if (arr.Length == 2 && p.Text.Contains("-"))
{
string newText = p.Text;
if (arr[0].StartsWith("- ", StringComparison.Ordinal) && arr[1].StartsWith("- ", StringComparison.Ordinal))
{
newText = "-" + arr[0].Remove(0, 2) + Environment.NewLine + "-" + arr[1].Remove(0, 2);
}
else if (arr[0].StartsWith("<i>- ", StringComparison.Ordinal) && arr[1].StartsWith("<i>- ", StringComparison.Ordinal))
{
newText = "<i>-" + arr[0].Remove(0, 5) + Environment.NewLine + "<i>-" + arr[1].Remove(0, 5);
}
else if (arr[0].StartsWith("<i>- ", StringComparison.Ordinal) && arr[1].StartsWith("- ", StringComparison.Ordinal))
{
newText = "<i>-" + arr[0].Remove(0, 5) + Environment.NewLine + "-" + arr[1].Remove(0, 2);
}
else if (arr[0].StartsWith("- ", StringComparison.Ordinal) && arr[1].StartsWith("<i>- ", StringComparison.Ordinal))
{
newText = "-" + arr[0].Remove(0, 2) + Environment.NewLine + "<i>-" + arr[1].Remove(0, 5);
}
else if ((arr[0].StartsWith("-", StringComparison.Ordinal) || arr[0].StartsWith("<i>-", StringComparison.Ordinal)) && arr[1].StartsWith("- ", StringComparison.Ordinal))
{
newText = "-" + arr[0] + Environment.NewLine + "-" + arr[1].Remove(0, 2);
}
else if (arr[0].StartsWith("- ", StringComparison.Ordinal) && (arr[1].StartsWith("-", StringComparison.Ordinal) || arr[1].StartsWith("<i>-", StringComparison.Ordinal)))
{
newText = "-" + arr[0].Remove(0, 2) + Environment.NewLine + "-" + arr[1];
}
if (newText != p.Text)
{
var fixedParagraph = new Paragraph(p, false) { Text = newText };
string comment = "Dual Speakers: Use a hyphen without a space";
controller.AddRecord(p, fixedParagraph, comment);
}
}
}
}
private static void AddSpaceAfterHyphenInDialogues(Subtitle subtitle, NetflixQualityController controller)
{
var sub = new Subtitle(subtitle);
for (int i = 0; i < sub.Paragraphs.Count; i++)
{
Paragraph p = new Paragraph(sub.Paragraphs[i]);
var arr = p.Text.SplitToLines();
if (arr.Length == 2 && p.Text.Contains("-") && arr[0].Length > 3 && arr[1].Length > 3)
{
string newText = p.Text;
if (arr[0][0] == '-' && char.IsLetter(arr[0][1]) && (arr[1].StartsWith("-", StringComparison.Ordinal) || arr[1].StartsWith("<i>-", StringComparison.Ordinal)))
{
newText = arr[0].Insert(1, " ") + Environment.NewLine + arr[1];
arr = newText.SplitToLines();
}
else if (arr[0].StartsWith("<i>-", StringComparison.Ordinal) && arr[0].Length > 5 && char.IsLetter(arr[0][4]) && (arr[1].StartsWith("-", StringComparison.Ordinal) || arr[1].StartsWith("<i>-", StringComparison.Ordinal)))
{
newText = arr[0].Insert(4, " ") + Environment.NewLine + arr[1];
arr = newText.SplitToLines();
}
if (arr[1][0] == '-' && char.IsLetter(arr[1][1]) && (arr[0].StartsWith("-", StringComparison.Ordinal) || arr[0].StartsWith("<i>-", StringComparison.Ordinal)))
{
newText = arr[0] + Environment.NewLine + arr[1].Insert(1, " ");
}
else if (arr[1].StartsWith("<i>-", StringComparison.Ordinal) && arr[1].Length > 5 && char.IsLetter(arr[1][4]) && (arr[0].StartsWith("-", StringComparison.Ordinal) || arr[0].StartsWith("<i>-", StringComparison.Ordinal)))
{
newText = arr[0] + Environment.NewLine + arr[1].Insert(4, " ");
}
if (newText != p.Text)
{
var fixedParagraph = new Paragraph(p, false) { Text = newText };
string comment = "Dual Speakers: Use a space after hyphen";
controller.AddRecord(p, fixedParagraph, comment);
}
}
}
}
}
}
@@ -22,13 +22,13 @@ public void Check(Subtitle subtitle, NetflixQualityController controller)
{
newText = "[" + newText.Substring(1, newText.Length - 2) + "]";
}
else if (arr.Length == 2 && arr[0].StartsWith("-") && arr[1].StartsWith("-"))
else if (arr.Length == 2 && arr[0].StartsWith("-", StringComparison.Ordinal) && arr[1].StartsWith("-", StringComparison.Ordinal))
{
if ((arr[0].StartsWith("-(") && arr[0].EndsWith(")")) || (arr[0].StartsWith("-{") && arr[0].EndsWith("}")))
if ((arr[0].StartsWith("-(", StringComparison.Ordinal) && arr[0].EndsWith(")", StringComparison.Ordinal)) || (arr[0].StartsWith("-{", StringComparison.Ordinal) && arr[0].EndsWith("}", StringComparison.Ordinal)))
{
arr[0] = "-[" + newText.Substring(2, newText.Length - 3) + "]";
}
if ((arr[1].StartsWith("-(") && arr[1].EndsWith(")")) || (arr[1].StartsWith("-{") && arr[1].EndsWith("}")))
if ((arr[1].StartsWith("-(", StringComparison.Ordinal) && arr[1].EndsWith(")", StringComparison.Ordinal)) || (arr[1].StartsWith("-{", StringComparison.Ordinal) && arr[1].EndsWith("}", StringComparison.Ordinal)))
{
arr[1] = "-[" + arr[1].Substring(2, arr[1].Length - 3) + "]";
}
@@ -10,7 +10,7 @@ public class NetflixQualityController
{
/// <summary>
/// Two letter language code
/// Two letter language code (e.g. "en" is English)
/// </summary>
public string Language { get; set; } = "en";
@@ -205,7 +205,7 @@ private List<INetflixQualityChecker> GetAllCheckers()
{
return new List<INetflixQualityChecker>
{
new NetflixCheckDialogeHyphenNoSpace(),
new NetflixCheckDialogeHyphenSpace(),
new NetflixCheckGlyph(),
new NetflixCheckMaxCps(),
new NetflixCheckMaxLineLength(),
@@ -54,14 +54,68 @@ public void TestNetflixCheckDialogeHyphenNoSpace()
sub.Paragraphs.Add(p2);
var controller = new NetflixQualityController();
var checker = new NetflixCheckDialogeHyphenNoSpace();
var checker = new NetflixCheckDialogeHyphenSpace();
checker.Check(sub, controller);
Assert.AreEqual(1, controller.Records.Count);
Assert.AreEqual(controller.Records[0].FixedParagraph.Text, "-Lorem ipsum dolor sit" + Environment.NewLine + "-nelit focasia venlit dokalalam dilars.");
}
[TestMethod]
public void TestNetflixCheckDialogeHyphenNoSpaceItalic()
{
var sub = new Subtitle();
var p1 = new Paragraph("<i>- Lorem ipsum dolor sit</i>" + Environment.NewLine + "<i>- nelit focasia venlit dokalalam dilars.</i>", 0, 4000);
sub.Paragraphs.Add(p1);
var p2 = new Paragraph("Lorem - ipsum.", 0, 1000);
sub.Paragraphs.Add(p2);
var controller = new NetflixQualityController();
var checker = new NetflixCheckDialogeHyphenSpace();
checker.Check(sub, controller);
Assert.AreEqual(1, controller.Records.Count);
Assert.AreEqual(controller.Records[0].FixedParagraph.Text, "<i>-Lorem ipsum dolor sit</i>" + Environment.NewLine + "<i>-nelit focasia venlit dokalalam dilars.</i>");
}
[TestMethod]
public void TestNetflixCheckDialogeHyphenAddSpace()
{
var sub = new Subtitle();
var p1 = new Paragraph("-Lorem ipsum dolor sit." + Environment.NewLine + "-Nelit focasia venlit dokalalam dilars.", 0, 4000);
sub.Paragraphs.Add(p1);
var p2 = new Paragraph("Lorem-ipsum.", 0, 1000);
sub.Paragraphs.Add(p2);
var controller = new NetflixQualityController() { Language = "fr" };
var checker = new NetflixCheckDialogeHyphenSpace();
checker.Check(sub, controller);
Assert.AreEqual(1, controller.Records.Count);
Assert.AreEqual(controller.Records[0].FixedParagraph.Text, "- Lorem ipsum dolor sit." + Environment.NewLine + "- Nelit focasia venlit dokalalam dilars.");
}
[TestMethod]
public void TestNetflixCheckDialogeHyphenAddSpaceItalic()
{
var sub = new Subtitle();
var p1 = new Paragraph("<i>-Lorem ipsum dolor sit.</i>" + Environment.NewLine + "<i>-Nelit focasia venlit dokalalam dilars.</i>", 0, 4000);
sub.Paragraphs.Add(p1);
var p2 = new Paragraph("Lorem-ipsum.", 0, 1000);
sub.Paragraphs.Add(p2);
var controller = new NetflixQualityController() { Language = "fr" };
var checker = new NetflixCheckDialogeHyphenSpace();
checker.Check(sub, controller);
Assert.AreEqual(1, controller.Records.Count);
Assert.AreEqual(controller.Records[0].FixedParagraph.Text, "<i>- Lorem ipsum dolor sit.</i>" + Environment.NewLine + "<i>- Nelit focasia venlit dokalalam dilars.</i>");
}
[TestMethod]
public void TestNetflixCheckMaxCps()
{

0 comments on commit 2701b5a

Please sign in to comment.