Merge pull request #10 from DSRCorporation/bugfix/netflix-qc-messages

Fixed Netflix QC
This commit is contained in:
pavel-belenko 2017-03-01 14:45:03 +03:00 committed by GitHub
commit e808acfaaa
11 changed files with 387 additions and 37 deletions

View File

@ -1991,12 +1991,14 @@ can edit in same subtitle file (collaboration)</Information>
<UndoX>Undo: {0}</UndoX>
</SpellCheck>
<NetflixQualityCheck>
<GlyphCheckSuccessfull>Character validation successful.</GlyphCheckSuccessfull>
<GlyphCheckFailed>Character validation failed. Refer to the Netflix Glyph List for valid characters. Please see the full report here: {0}.</GlyphCheckFailed>
<GlyphCheckReport>Invalid character {0} found at column {1}.</GlyphCheckReport>
<WhiteSpaceCheckSuccessfull>White space validation successful.</WhiteSpaceCheckSuccessfull>
<WhiteSpaceCheckFailed>White space validation failed. Please see the full report here: {0}.</WhiteSpaceCheckFailed>
<GlyphCheckSuccessfull>Character validation has been successful.</GlyphCheckSuccessfull>
<GlyphCheckFailed>Character validation has failed.</GlyphCheckFailed>
<GlyphCheckReport>Invalid character {0} found at column {0}</GlyphCheckReport>
<WhiteSpaceCheckSuccessfull>White space validation has been successful.</WhiteSpaceCheckSuccessfull>
<WhiteSpaceCheckFailed>White space validation has failed.</WhiteSpaceCheckFailed>
<WhiteSpaceCheckReport>Invalid white space found at column {0}.</WhiteSpaceCheckReport>
<ReportPrompt>Please see full report here: {0}.</ReportPrompt>
<SavingError>Report cannot be saved.</SavingError>
</NetflixQualityCheck>
<Split>
<Title>Split</Title>

View File

@ -2286,13 +2286,16 @@ can edit in same subtitle file (collaboration)",
NetflixQualityCheck = new LanguageStructure.NetflixQualityCheck
{
GlyphCheckSuccessfull = "Character validation successful.",
GlyphCheckFailed = "Character validation failed. Refer to the Netflix Glyph List for valid characters. Please see the full report here: {0}.",
GlyphCheckReport = "Invalid character {0} found at column {1}.",
GlyphCheckSuccessfull = "Character validation has been successful.",
GlyphCheckFailed = "Character validation has failed.",
GlyphCheckReport = "Invalid character {0} found at column {0}",
WhiteSpaceCheckSuccessfull = "White space validation successful.",
WhiteSpaceCheckFailed = "White space validation failed. Please see the full report here: {0}.",
WhiteSpaceCheckReport = "Invalid white space found at column {0}."
WhiteSpaceCheckSuccessfull = "White space validation has been successful.",
WhiteSpaceCheckFailed = "White space validation has failed.",
WhiteSpaceCheckReport = "Invalid white space found at column {0}.",
ReportPrompt = "Please see full report here: {0}.",
SavingError = "Report cannot be saved."
};
Split = new LanguageStructure.Split

View File

@ -5407,6 +5407,12 @@ namespace Nikse.SubtitleEdit.Core
case "NetflixQualityCheck/WhiteSpaceCheckReport":
language.NetflixQualityCheck.WhiteSpaceCheckReport = reader.Value;
break;
case "NetflixQualityCheck/ReportPrompt":
language.NetflixQualityCheck.ReportPrompt = reader.Value;
break;
case "NetflixQualityCheck/SavingError":
language.NetflixQualityCheck.SavingError = reader.Value;
break;
case "Split/Title":
language.Split.Title = reader.Value;
break;

View File

@ -2173,6 +2173,9 @@
public string WhiteSpaceCheckSuccessfull { get; set; }
public string WhiteSpaceCheckFailed { get; set; }
public string WhiteSpaceCheckReport { get; set; }
public string ReportPrompt { get; set; }
public string SavingError { get; set; }
}
public class Split

View File

@ -24,7 +24,7 @@ namespace Nikse.SubtitleEdit.Core.NetflixQualityCheck
{
string safeContext = Context;
safeContext = safeContext.Replace("\"", "\"\"");
safeContext = safeContext.Replace("\r\n", "\n");
safeContext = safeContext.Replace("\r", "\\r");
safeContext = safeContext.Replace("\n", "\\n");
safeContext = string.Format("\"{0}\"", safeContext);

View File

@ -8,17 +8,40 @@ namespace Nikse.SubtitleEdit.Core.NetflixQualityCheck
{
public class NetflixWhiteSpaceChecker : INetflixQualityChecker
{
private void AddWhiteSpaceWarning(Paragraph p, NetflixQualityReportBuilder report, int pos)
{
string timecode = p.StartTime.ToHHMMSSFF();
string context = NetflixQualityReportBuilder.StringContext(p.Text, pos, 6);
string comment = string.Format(Configuration.Settings.Language.NetflixQualityCheck.WhiteSpaceCheckReport, pos);
report.AddRecord(timecode, context, comment);
}
public void Check(Subtitle subtitle, NetflixQualityReportBuilder report)
{
foreach (Paragraph p in subtitle.Paragraphs)
{
// Line endings
if (Regex.Match(p.Text, @"^( |\n|\r\n)[^\s]").Success)
{
AddWhiteSpaceWarning(p, report, 1);
}
if (Regex.Match(p.Text, @"[^\s]( |\n|\r\n)$").Success)
{
AddWhiteSpaceWarning(p, report, p.Text.Length);
}
// Spaces before punctuation
foreach (Match m in Regex.Matches(p.Text, @"[^\s]( |\n|\r\n)[!?).,]"))
{
AddWhiteSpaceWarning(p, report, m.Index + 1);
}
// 2+ consequent spaces
foreach (Match m in Regex.Matches(p.Text, "( |\n|\r\n){2,}"))
{
string timecode = p.StartTime.ToHHMMSSFF();
string context = NetflixQualityReportBuilder.StringContext(p.Text, m.Index, 6);
string comment = string.Format(Configuration.Settings.Language.NetflixQualityCheck.WhiteSpaceCheckReport, m.Index);
report.AddRecord(timecode, context, comment);
AddWhiteSpaceWarning(p, report, m.Index);
}
}
}

View File

@ -20444,48 +20444,87 @@ namespace Nikse.SubtitleEdit.Forms
private void NetflixGlyphCheck(bool showSuccessMessage = true)
{
// Get subtitle
ReloadFromSourceView();
string subtitle = _subtitle.ToText(GetCurrentSubtitleFormat());
// Check
string fileName = string.IsNullOrEmpty(_fileName) ? "untitledSubtitle" : Path.GetFileNameWithoutExtension(_fileName);
List<string> messages = new List<string>();
string firstReportFile = null;
// Glyph check
NetflixQualityReportBuilder glyphCheckReport = new NetflixQualityReportBuilder();
NetflixGlyphChecker glyphChecker = new NetflixGlyphChecker();
glyphChecker.Check(_subtitle, glyphCheckReport);
NetflixQualityReportBuilder whiteSpaceCheckReport = new NetflixQualityReportBuilder();
NetflixWhiteSpaceChecker whiteSpaceChecker = new NetflixWhiteSpaceChecker();
whiteSpaceChecker.Check(_subtitle, whiteSpaceCheckReport);
string fileName = string.IsNullOrEmpty(_fileName) ? "untitledSubtitle" : Path.GetFileNameWithoutExtension(_fileName);
List<string> messages = new List<string>();
if (!glyphCheckReport.IsEmpty)
if (!glyphCheckReport.IsEmpty) // There are warnings
{
string reportPath = Path.GetTempPath() + fileName + "_NetflixGlyphCheck.csv";
File.WriteAllText(reportPath, glyphCheckReport.ExportCSV());
messages.Add(string.Format(Configuration.Settings.Language.NetflixQualityCheck.GlyphCheckFailed, reportPath));
try
{
File.WriteAllText(reportPath, glyphCheckReport.ExportCSV());
string msgFormat = string.Format("{0} {1}",
Configuration.Settings.Language.NetflixQualityCheck.GlyphCheckFailed,
Configuration.Settings.Language.NetflixQualityCheck.ReportPrompt);
messages.Add(string.Format(msgFormat , reportPath));
firstReportFile = firstReportFile ?? reportPath;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
messages.Add(string.Format("{0} {1}",
Configuration.Settings.Language.NetflixQualityCheck.GlyphCheckFailed,
Configuration.Settings.Language.NetflixQualityCheck.SavingError));
}
}
else if (showSuccessMessage)
else if (showSuccessMessage) // Success
{
messages.Add(Configuration.Settings.Language.NetflixQualityCheck.GlyphCheckSuccessfull);
}
if (!whiteSpaceCheckReport.IsEmpty)
// Space check
NetflixQualityReportBuilder whiteSpaceCheckReport = new NetflixQualityReportBuilder();
NetflixWhiteSpaceChecker whiteSpaceChecker = new NetflixWhiteSpaceChecker();
whiteSpaceChecker.Check(_subtitle, whiteSpaceCheckReport);
if (!whiteSpaceCheckReport.IsEmpty) // There are warnings
{
string reportPath = Path.GetTempPath() + fileName + "_NetflixWhiteSpaceCheck.csv";
File.WriteAllText(reportPath, whiteSpaceCheckReport.ExportCSV());
messages.Add(string.Format(Configuration.Settings.Language.NetflixQualityCheck.WhiteSpaceCheckFailed, reportPath));
try
{
File.WriteAllText(reportPath, whiteSpaceCheckReport.ExportCSV());
string msgFormat = string.Format("{0} {1}",
Configuration.Settings.Language.NetflixQualityCheck.WhiteSpaceCheckFailed,
Configuration.Settings.Language.NetflixQualityCheck.ReportPrompt);
messages.Add(string.Format(msgFormat, reportPath));
firstReportFile = firstReportFile ?? reportPath;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
messages.Add(string.Format("{0} {1}",
Configuration.Settings.Language.NetflixQualityCheck.WhiteSpaceCheckFailed,
Configuration.Settings.Language.NetflixQualityCheck.SavingError));
}
}
else if (showSuccessMessage)
else if (showSuccessMessage) // Success
{
messages.Add(Configuration.Settings.Language.NetflixQualityCheck.WhiteSpaceCheckSuccessfull);
}
if (messages.Count != 0)
{
MessageBox.Show(String.Join(Environment.NewLine, messages.ToArray()), Configuration.Settings.Language.Main.Menu.ToolBar.NetflixQualityCheck);
NetflixQCResult dialog = new NetflixQCResult(string.Join(Environment.NewLine, messages), firstReportFile);
dialog.ShowDialog(this);
}
}

93
src/Forms/NetflixQCResult.Designer.cs generated Normal file
View File

@ -0,0 +1,93 @@
namespace Nikse.SubtitleEdit.Forms
{
partial class NetflixQCResult
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnOk = new System.Windows.Forms.Button();
this.btnOpen = new System.Windows.Forms.Button();
this.lblText = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnOk
//
this.btnOk.Anchor = System.Windows.Forms.AnchorStyles.None;
this.btnOk.Location = new System.Drawing.Point(162, 64);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 23);
this.btnOk.TabIndex = 0;
this.btnOk.Text = "Ok";
this.btnOk.UseVisualStyleBackColor = true;
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// btnOpen
//
this.btnOpen.Anchor = System.Windows.Forms.AnchorStyles.None;
this.btnOpen.Location = new System.Drawing.Point(46, 64);
this.btnOpen.Name = "btnOpen";
this.btnOpen.Size = new System.Drawing.Size(110, 23);
this.btnOpen.TabIndex = 1;
this.btnOpen.Text = "Open file location";
this.btnOpen.UseVisualStyleBackColor = true;
this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);
//
// lblText
//
this.lblText.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblText.AutoSize = true;
this.lblText.Location = new System.Drawing.Point(12, 9);
this.lblText.Name = "lblText";
this.lblText.Size = new System.Drawing.Size(90, 13);
this.lblText.TabIndex = 2;
this.lblText.Text = "Message to show";
//
// NetflixQCResult
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(296, 99);
this.Controls.Add(this.lblText);
this.Controls.Add(this.btnOpen);
this.Controls.Add(this.btnOk);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "NetflixQCResult";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Netflix quality check";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.Button btnOpen;
private System.Windows.Forms.Label lblText;
}
}

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace Nikse.SubtitleEdit.Forms
{
public partial class NetflixQCResult : Form
{
private string Message { get; set; }
private string FileToLocate { get; set; }
public NetflixQCResult(string message, string fileToLocate)
{
InitializeComponent();
Message = message;
FileToLocate = fileToLocate;
lblText.Text = Message;
Width = Math.Max(lblText.Width + lblText.Left * 3, 300);
btnOpen.Visible = !string.IsNullOrEmpty(fileToLocate);
}
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == Keys.Escape)
{
Close();
}
return base.ProcessDialogKey(keyData);
}
private void btnOk_Click(object sender, EventArgs e)
{
Close();
}
private void btnOpen_Click(object sender, EventArgs e)
{
Process.Start("explorer.exe", string.Format(@"/select,""{0}"" ", FileToLocate));
Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -336,6 +336,12 @@
<Compile Include="Forms\MultipleReplaceNewGroup.Designer.cs">
<DependentUpon>MultipleReplaceNewGroup.cs</DependentUpon>
</Compile>
<Compile Include="Forms\NetflixQCResult.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\NetflixQCResult.Designer.cs">
<DependentUpon>NetflixQCResult.cs</DependentUpon>
</Compile>
<Compile Include="Forms\NuendoProperties.cs">
<SubType>Form</SubType>
</Compile>
@ -1038,6 +1044,9 @@
<EmbeddedResource Include="Forms\MultipleReplaceNewGroup.resx">
<DependentUpon>MultipleReplaceNewGroup.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\NetflixQCResult.resx">
<DependentUpon>NetflixQCResult.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\NuendoProperties.resx">
<DependentUpon>NuendoProperties.cs</DependentUpon>
</EmbeddedResource>