Fix for .ismt loading

This commit is contained in:
niksedk 2023-03-20 20:05:38 +01:00
parent a8e5eb8596
commit 996a84df64
3 changed files with 17 additions and 10 deletions

View File

@ -24,10 +24,16 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
var fine = 0; var fine = 0;
var errors = 0; var errors = 0;
var sb = new StringBuilder(); var sb = new StringBuilder();
foreach (var line in lines) for (var index = 0; index < lines.Count; index++)
{ {
var line = lines[index];
if (index == 0 && line.StartsWith("<tt xmlns"))
{
return false;
}
sb.Append(line); sb.Append(line);
if (line.IndexOf(':') > 0 && if (line.IndexOf(':') > 0 &&
(CsvLine.IsMatch(line) || (CsvLine.IsMatch(line) ||
CsvLineNoQuotes.IsMatch(line) || CsvLineNoQuotes.IsMatch(line) ||
CsvLineAllQuotes.IsMatch(line) || CsvLineAllQuotes.IsMatch(line) ||

View File

@ -8,6 +8,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{ {
public class UnknownSubtitle65 : SubtitleFormat public class UnknownSubtitle65 : SubtitleFormat
{ {
private readonly Regex _regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d,\d\d:\d\d:\d\d$", RegexOptions.Compiled);
private enum ExpectingLine private enum ExpectingLine
{ {
TimeCodes, TimeCodes,
@ -57,8 +60,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{ {
var regexTimeCodes = new Regex(@"^\d\d:\d\d:\d\d,\d\d:\d\d:\d\d$", RegexOptions.Compiled);
var paragraph = new Paragraph(); var paragraph = new Paragraph();
ExpectingLine expecting = ExpectingLine.TimeCodes; ExpectingLine expecting = ExpectingLine.TimeCodes;
_errorCount = 0; _errorCount = 0;
@ -66,7 +67,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
subtitle.Paragraphs.Clear(); subtitle.Paragraphs.Clear();
foreach (string line in lines) foreach (string line in lines)
{ {
if (line.Length == 17 && regexTimeCodes.IsMatch(line)) if (line.Length == 17 && _regexTimeCodes.IsMatch(line))
{ {
string[] parts = line.Split(new[] { ':', ',', '.', ' ' }, StringSplitOptions.RemoveEmptyEntries); string[] parts = line.Split(new[] { ':', ',', '.', ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 6) if (parts.Length == 6)

View File

@ -11,6 +11,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
/// </summary> /// </summary>
public class UnknownSubtitle7 : SubtitleFormat public class UnknownSubtitle7 : SubtitleFormat
{ {
private readonly Regex _regexTimeCode = new Regex(@"^\d\d:\d\d:\d\d:\d\d ", RegexOptions.Compiled);
private readonly Regex _regexTimeCodeEnd = new Regex(@"^\d\d:\d\d:\d\d:\d\d\t$", RegexOptions.Compiled);
private enum ExpectingLine private enum ExpectingLine
{ {
TimeStart, TimeStart,
@ -42,9 +45,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName) public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{ {
var regexTimeCode = new Regex(@"^\d\d:\d\d:\d\d:\d\d ", RegexOptions.Compiled);
var regexTimeCodeEnd = new Regex(@"^\d\d:\d\d:\d\d:\d\d\t$", RegexOptions.Compiled);
var paragraph = new Paragraph(); var paragraph = new Paragraph();
var expecting = ExpectingLine.TimeStart; var expecting = ExpectingLine.TimeStart;
_errorCount = 0; _errorCount = 0;
@ -54,7 +54,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
foreach (string line in lines) foreach (string line in lines)
{ {
count++; count++;
if (regexTimeCode.IsMatch(line)) if (_regexTimeCode.IsMatch(line))
{ {
string[] parts = line.Substring(0, 11).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries); string[] parts = line.Substring(0, 11).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 4) if (parts.Length == 4)
@ -81,7 +81,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
} }
} }
} }
else if (regexTimeCodeEnd.IsMatch(line) || (count == lines.Count && regexTimeCodeEnd.IsMatch(line + "\t"))) else if (_regexTimeCodeEnd.IsMatch(line) || (count == lines.Count && _regexTimeCodeEnd.IsMatch(line + "\t")))
{ {
string[] parts = line.Substring(0, 11).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries); string[] parts = line.Substring(0, 11).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 4) if (parts.Length == 4)