mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 15:02:35 +01:00
parent
26e410efc0
commit
919d2a4adc
85
src/libse/SubtitleFormats/Drtic.cs
Normal file
85
src/libse/SubtitleFormats/Drtic.cs
Normal 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}";
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
new DCinemaSmpte2014(),
|
||||
new DfxpBasic(),
|
||||
new DigiBeta(),
|
||||
new Drtic(),
|
||||
new DvdStudioPro(),
|
||||
new DvdStudioProSpaceOne(),
|
||||
new DvdStudioProSpaceOneSemicolon(),
|
||||
|
Loading…
Reference in New Issue
Block a user