Add support for .dtc subs - thx wesskywalker :)

work on #5218
This commit is contained in:
niksedk 2021-07-24 23:47:53 +02:00
parent 26e410efc0
commit 919d2a4adc
3 changed files with 92 additions and 1 deletions

View File

@ -0,0 +1,85 @@
using Nikse.SubtitleEdit.Core.Common;
using System;
using System.Collections.Generic;
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class Drtic : MicroDvd
{
public override string Extension => ".dtc";
public override string Name => "Drtic";
public override bool IsTimeBased => false;
public override bool IsMine(List<string> lines, string fileName)
{
var headerFound = false;
var trimmedLines = new List<string>();
int errors = 0;
foreach (string line in lines)
{
if (!string.IsNullOrWhiteSpace(line))
{
if (line.StartsWith("[JRT2:", StringComparison.Ordinal))
{
headerFound = true;
}
else if (line.Contains('{'))
{
string s = RemoveIllegalSpacesAndFixEmptyCodes(line);
if (RegexMicroDvdLine.IsMatch(s))
{
trimmedLines.Add(s);
}
else
{
errors++;
}
}
else
{
errors++;
}
}
}
return headerFound && trimmedLines.Count > errors;
}
private static string RemoveIllegalSpacesAndFixEmptyCodes(string line)
{
if (string.IsNullOrEmpty(line) || line.Length > 2000)
{
return line;
}
int index = line.IndexOf('}');
if (index >= 0 && index + 1 < line.Length)
{
index = line.IndexOf('}', index + 1);
if (index >= 0 && index + 1 < line.Length)
{
var indexOfBrackets = line.IndexOf("{}", StringComparison.Ordinal);
if (indexOfBrackets >= 0 && indexOfBrackets < index)
{
line = line.Insert(indexOfBrackets + 1, "0"); // set empty time codes to zero
index++;
}
while (line.Contains(' ') && line.IndexOf(' ') < index)
{
line = line.Remove(line.IndexOf(' '), 1);
index--;
}
}
}
return line;
}
public override string ToText(Subtitle subtitle, string title)
{
return $"[JRT2: {subtitle.Paragraphs.Count} 0 ]{Environment.NewLine}{base.ToText(subtitle, title)}{Environment.NewLine}";
}
}
}

View File

@ -8,7 +8,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class MicroDvd : SubtitleFormat
{
private static readonly Regex RegexMicroDvdLine = new Regex(@"^\{-?\d+}\{-?\d+}.*$", RegexOptions.Compiled);
internal static readonly Regex RegexMicroDvdLine = new Regex(@"^\{-?\d+}\{-?\d+}.*$", RegexOptions.Compiled);
public string Errors { get; private set; }
private StringBuilder _errors;
private int _lineNumber;
@ -39,12 +39,17 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
errors++;
}
}
else if (line.StartsWith("[JRT2:", StringComparison.Ordinal))
{
return false;
}
else
{
errors++;
}
}
}
Errors = null;
return trimmedLines.Count > errors;
}

View File

@ -69,6 +69,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
new DCinemaSmpte2014(),
new DfxpBasic(),
new DigiBeta(),
new Drtic(),
new DvdStudioPro(),
new DvdStudioProSpaceOne(),
new DvdStudioProSpaceOneSemicolon(),