SubtitleEdit/libse/SubtitleFormats/Dost.cs

104 lines
3.6 KiB
C#
Raw Normal View History

2016-02-06 07:52:53 +01:00
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class Dost : SubtitleFormat
{
private static readonly Regex RegexTimeCodes = new Regex(@"^\d\d\d\d\t\d\d:\d\d:\d\d:\d\d\t\d\d:\d\d:\d\d:\d\d\t", RegexOptions.Compiled);
public override string Extension => ".dost";
2016-02-06 07:52:53 +01:00
public override string Name => "DOST";
2016-02-06 07:52:53 +01:00
public override bool IsMine(List<string> lines, string fileName)
{
var sb = new StringBuilder();
foreach (string line in lines)
2019-01-19 14:40:37 +01:00
{
2016-02-06 07:52:53 +01:00
sb.AppendLine(line);
2019-01-19 14:40:37 +01:00
}
2016-02-06 07:52:53 +01:00
if (!sb.ToString().Contains(Environment.NewLine + "NO\tINTIME"))
2019-01-19 14:40:37 +01:00
{
2016-02-06 07:52:53 +01:00
return false;
2019-01-19 14:40:37 +01:00
}
2016-02-06 07:52:53 +01:00
if (!sb.ToString().Contains("$FORMAT"))
2019-01-19 14:40:37 +01:00
{
2016-02-06 07:52:53 +01:00
return false;
2019-01-19 14:40:37 +01:00
}
2016-02-06 07:52:53 +01:00
2017-08-03 12:43:52 +02:00
return base.IsMine(lines, fileName);
2016-02-06 07:52:53 +01:00
}
public override string ToText(Subtitle subtitle, string title)
{
return "Not implemented";
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
//0001 01:25:59:21 01:26:00:20 0 0 BK02-total_0001.png 0 0
Paragraph p = null;
subtitle.Paragraphs.Clear();
_errorCount = 0;
foreach (string line in lines)
{
string s = line;
if (RegexTimeCodes.IsMatch(s))
{
var temp = s.Split('\t');
if (temp.Length > 7)
{
string start = temp[1];
string end = temp[2];
string text = temp[5];
try
{
p = new Paragraph(DecodeTimeCodeFramesFourParts(start.Split(':')), DecodeTimeCodeFramesFourParts(end.Split(':')), text);
2016-02-06 07:52:53 +01:00
subtitle.Paragraphs.Add(p);
}
catch (Exception exception)
{
_errorCount++;
System.Diagnostics.Debug.WriteLine(exception.Message);
}
}
}
else if (line.StartsWith("$DROP=", StringComparison.Ordinal))
2016-02-06 07:52:53 +01:00
{
s = s.Remove(0, "$DROP=".Length);
int frameRate;
if (int.TryParse(s, out frameRate))
{
double f = frameRate / TimeCode.BaseUnit;
if (f > 10 && f < 500)
2019-01-19 14:40:37 +01:00
{
2016-02-06 07:52:53 +01:00
Configuration.Settings.General.CurrentFrameRate = f;
2019-01-19 14:40:37 +01:00
}
if (BatchSourceFrameRate.HasValue)
{
Configuration.Settings.General.CurrentFrameRate = BatchSourceFrameRate.Value;
}
2016-02-06 07:52:53 +01:00
}
}
else if (string.IsNullOrWhiteSpace(line) || line.StartsWith('$'))
{
// skip empty lines or lines starting with $
}
else if (!string.IsNullOrWhiteSpace(line) && p != null)
{
_errorCount++;
}
}
subtitle.Renumber();
}
}
}