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 errors = 0;
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);
if (line.IndexOf(':') > 0 &&
if (line.IndexOf(':') > 0 &&
(CsvLine.IsMatch(line) ||
CsvLineNoQuotes.IsMatch(line) ||
CsvLineAllQuotes.IsMatch(line) ||

View File

@ -8,6 +8,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
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
{
TimeCodes,
@ -57,8 +60,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
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();
ExpectingLine expecting = ExpectingLine.TimeCodes;
_errorCount = 0;
@ -66,7 +67,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
subtitle.Paragraphs.Clear();
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);
if (parts.Length == 6)

View File

@ -11,6 +11,9 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
/// </summary>
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
{
TimeStart,
@ -42,9 +45,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
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 expecting = ExpectingLine.TimeStart;
_errorCount = 0;
@ -54,7 +54,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
foreach (string line in lines)
{
count++;
if (regexTimeCode.IsMatch(line))
if (_regexTimeCode.IsMatch(line))
{
string[] parts = line.Substring(0, 11).Split(SplitCharColon, StringSplitOptions.RemoveEmptyEntries);
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);
if (parts.Length == 4)