SubtitleEdit/libse/NetflixQualityCheck/NetflixCheckMaxCps.cs
2017-03-24 22:41:17 +01:00

38 lines
1.5 KiB
C#

using System.Globalization;
namespace Nikse.SubtitleEdit.Core.NetflixQualityCheck
{
public class NetflixCheckMaxCps : INetflixQualityChecker
{
/// <summary>
/// Speed - max 17 (for most languages) characters per second
/// </summary>
public void Check(Subtitle subtitle, NetflixQualityController controller)
{
var oldIgnoreWhiteSpace = Configuration.Settings.General.CharactersPerSecondsIgnoreWhiteSpace;
try
{
foreach (Paragraph p in subtitle.Paragraphs)
{
var charactersPerSeconds = Utilities.GetCharactersPerSecond(p);
if (charactersPerSeconds > controller.CharactersPerSecond)
{
var fixedParagraph = new Paragraph(p, false);
while (Utilities.GetCharactersPerSecond(fixedParagraph) > controller.CharactersPerSecond)
{
fixedParagraph.EndTime.TotalMilliseconds++;
}
string comment = "Maximum " + controller.CharactersPerSecond + " characters per second";
controller.AddRecord(p, fixedParagraph, comment, charactersPerSeconds.ToString(CultureInfo.InvariantCulture));
}
}
}
finally
{
Configuration.Settings.General.CharactersPerSecondsIgnoreWhiteSpace = oldIgnoreWhiteSpace;
}
}
}
}