mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Display errors in SubRip files after loading (if there were any)
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1232 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
1c6dd18c0f
commit
a244c8384b
@ -238,8 +238,11 @@ namespace Nikse.SubtitleEdit.Controls
|
||||
{
|
||||
_subtitleText = value;
|
||||
|
||||
bool alignLeft = _subtitleText.StartsWith("{\\a1}") || _subtitleText.StartsWith("{\\a5}") || _subtitleText.StartsWith("{\\a9}");
|
||||
bool alignRight = _subtitleText.StartsWith("{\\a3}") || _subtitleText.StartsWith("{\\a7}") || _subtitleText.StartsWith("{\\a11}");
|
||||
bool alignLeft = _subtitleText.StartsWith("{\\a1}") || _subtitleText.StartsWith("{\\a5}") || _subtitleText.StartsWith("{\\a9}") || // sub station alpha
|
||||
_subtitleText.StartsWith("{\\an1}") || _subtitleText.StartsWith("{\\an4}") || _subtitleText.StartsWith("{\\an7}"); // advanced sub station alpha
|
||||
|
||||
bool alignRight = _subtitleText.StartsWith("{\\a3}") || _subtitleText.StartsWith("{\\a7}") || _subtitleText.StartsWith("{\\a11}") || // sub station alpha
|
||||
_subtitleText.StartsWith("{\\an3}") || _subtitleText.StartsWith("{\\an6}") || _subtitleText.StartsWith("{\\an9}"); // advanced sub station alpha
|
||||
|
||||
// remove styles for display text (except italic)
|
||||
string text = RemoveSubStationAlphaFormatting(_subtitleText);
|
||||
|
@ -2131,7 +2131,13 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
string errors = AdvancedSubStationAlpha.CheckForErrors(_subtitle.Header);
|
||||
if (!string.IsNullOrEmpty(errors))
|
||||
MessageBox.Show(errors);
|
||||
MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
else if (format.GetType() == typeof(SubRip))
|
||||
{
|
||||
string errors = (format as SubRip).Errors;
|
||||
if (!string.IsNullOrEmpty(errors))
|
||||
MessageBox.Show((format as SubRip).Errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -3570,12 +3576,19 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
index++;
|
||||
}
|
||||
|
||||
if (format.FriendlyName == new AdvancedSubStationAlpha().FriendlyName || format.FriendlyName == new SubStationAlpha().FriendlyName)
|
||||
if (format.GetType() == typeof(AdvancedSubStationAlpha) || format.GetType() == typeof(SubStationAlpha))
|
||||
{
|
||||
string errors = AdvancedSubStationAlpha.CheckForErrors(_subtitle.Header);
|
||||
if (!string.IsNullOrEmpty(errors))
|
||||
MessageBox.Show(errors);
|
||||
MessageBox.Show(errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
else if (format.GetType() == typeof(SubRip))
|
||||
{
|
||||
string errors = (format as SubRip).Errors;
|
||||
if (!string.IsNullOrEmpty(errors))
|
||||
MessageBox.Show((format as SubRip).Errors, Title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -781,6 +781,8 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
TextFiles = "Text files",
|
||||
ExportPlainTextAs = "Export plain text as",
|
||||
SubtitleExported = "Subtitle exported",
|
||||
LineNumberXErrorReadingTimeCodeFromSourceLineY = "Line {0} - error reading time code: {1}",
|
||||
LineNumberXExpectedNumberFromSourceLineY = "Line {0} - expected subtitle number: {1}",
|
||||
|
||||
Menu = new LanguageStructure.Main.MainMenu
|
||||
{
|
||||
|
@ -721,6 +721,9 @@
|
||||
public string ExportPlainTextAs { get; set; }
|
||||
public string TextFiles { get; set; }
|
||||
public string SubtitleExported { get; set; }
|
||||
public string LineNumberXErrorReadingTimeCodeFromSourceLineY { get; set; }
|
||||
public string LineNumberXExpectedNumberFromSourceLineY { get; set; }
|
||||
|
||||
|
||||
public class MainMenu
|
||||
{
|
||||
|
@ -7,6 +7,10 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
public class SubRip : SubtitleFormat
|
||||
{
|
||||
public string Errors { get; private set; }
|
||||
private StringBuilder _errors;
|
||||
private int _lineNumber;
|
||||
|
||||
enum ExpectingLine
|
||||
{
|
||||
Number,
|
||||
@ -63,6 +67,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
bool doRenum = false;
|
||||
_errors = new StringBuilder();
|
||||
_lineNumber = 0;
|
||||
|
||||
_paragraph = new Paragraph();
|
||||
_expecting = ExpectingLine.Number;
|
||||
@ -71,6 +77,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
subtitle.Paragraphs.Clear();
|
||||
for (int i=0; i<lines.Count; i++)
|
||||
{
|
||||
_lineNumber++;
|
||||
string line = lines[i].TrimEnd();
|
||||
line = line.Trim(Convert.ToChar(127)); // 127=delete acscii
|
||||
|
||||
@ -101,6 +108,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
|
||||
if (doRenum)
|
||||
subtitle.Renumber(1);
|
||||
|
||||
Errors = _errors.ToString();
|
||||
}
|
||||
|
||||
private void ReadLine(Subtitle subtitle, string line, string next)
|
||||
@ -115,6 +124,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
}
|
||||
else if (line.Trim().Length > 0)
|
||||
{
|
||||
if (_errors.Length < 2000)
|
||||
_errors.AppendLine(string.Format(Configuration.Settings.Language.Main.LineNumberXExpectedNumberFromSourceLineY, _lineNumber, line));
|
||||
_errorCount++;
|
||||
}
|
||||
break;
|
||||
@ -126,6 +137,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
}
|
||||
else if (line.Trim().Length > 0)
|
||||
{
|
||||
if (_errors.Length < 2000)
|
||||
_errors.AppendLine(string.Format(Configuration.Settings.Language.Main.LineNumberXErrorReadingTimeCodeFromSourceLineY, _lineNumber, line));
|
||||
_errorCount++;
|
||||
_expecting = ExpectingLine.Number ; // lets go to next paragraph
|
||||
}
|
||||
@ -180,20 +193,13 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
private string RemoveBadChars(string line)
|
||||
{
|
||||
line = line.Replace("\0", " ");
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
private bool TryReadTimeCodesLine(string line, Paragraph paragraph)
|
||||
{
|
||||
{
|
||||
line = line.Replace("،", ",");
|
||||
|
||||
line = line.Trim();
|
||||
line = line.Replace(": ", ":"); // I've seen this
|
||||
line = line.Replace(" :", ":");
|
||||
line = line.Replace(" ,", ",");
|
||||
line = line.Replace(", ", ",");
|
||||
|
||||
// Fix some badly formatted separator sequences - anything can happen if you manually edit ;)
|
||||
line = line.Replace(" -> ", " --> "); // I've seen this
|
||||
line = line.Replace(" - > ", " --> ");
|
||||
@ -201,12 +207,17 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
line = line.Replace(" -- > ", " --> ");
|
||||
line = line.Replace(" - -> ", " --> ");
|
||||
line = line.Replace(" -->> ", " --> ");
|
||||
line = line.Replace(" ---> ", " --> ");
|
||||
|
||||
// Removed stuff after timecodes - like subtitle position
|
||||
// - example of position info: 00:02:26,407 --> 00:02:31,356 X1:100 X2:100 Y1:100 Y2:100
|
||||
if (line.Length > 30 && line[30] == ' ')
|
||||
line = line.Substring(0, 29);
|
||||
|
||||
// removes all extra spaces
|
||||
line = line.Replace(" ", string.Empty).Replace("-->", " --> ");
|
||||
line = line.Trim();
|
||||
|
||||
// Fix a few more cases of wrong time codes, seen this: 00.00.02,000 --> 00.00.04,000
|
||||
line = line.Replace('.', ':');
|
||||
if (line.Length >= 29 && ":;".Contains(line[8].ToString()))
|
||||
|
Loading…
Reference in New Issue
Block a user