Add new sub format - thx thehulk :)

This commit is contained in:
niksedk 2019-05-05 17:34:04 +02:00
parent 9b95a1a61f
commit c106a11790
3 changed files with 77 additions and 1 deletions

View File

@ -209,6 +209,7 @@
<Compile Include="SubtitleFormats\TimedText200604Ooyala.cs" />
<Compile Include="SubtitleFormats\TranscriptiveJson.cs" />
<Compile Include="SubtitleFormats\UnknownSubtitle88.cs" />
<Compile Include="SubtitleFormats\UnknownSubtitle90.cs" />
<Compile Include="TinyJsonParser.cs" />
<Compile Include="Language.cs" />
<Compile Include="LanguageAutoDetect.cs" />

View File

@ -281,7 +281,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
new UnknownSubtitle86(),
new UnknownSubtitle87(),
new UnknownSubtitle88(),
new UnknownSubtitle89()
new UnknownSubtitle89(),
new UnknownSubtitle90()
};
string path = Configuration.PluginsDirectory;

View File

@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class UnknownSubtitle90 : SubtitleFormat
{
//data_000001 1 0.13 0.63 Hello
private static readonly Regex RegexTimeCodes = new Regex(@"^data_\d+ \d \d+\.\d+ \d+\.\d+ ", RegexOptions.Compiled);
public override string Extension => ".ctm";
public override string Name => "Unknown 90";
public override string ToText(Subtitle subtitle, string title)
{
var sb = new StringBuilder();
const string writeFormat = "data_000001 1 {0:0.##} {1:0.##} {2}";
foreach (Paragraph p in subtitle.Paragraphs)
{
sb.AppendLine(string.Format(writeFormat, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.Duration), HtmlUtil.RemoveHtmlTags(p.Text.Replace(Environment.NewLine, "<br>"))));
}
return sb.ToString();
}
private static double EncodeTimeCode(TimeCode time)
{
return time.TotalSeconds;
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
subtitle.Paragraphs.Clear();
foreach (string line in lines)
{
var match = RegexTimeCodes.Match(line);
if (match.Success)
{
var arr = match.Value.Split(' ');
string text = line.Remove(0, match.Length).Trim();
text = text.Replace("<br>", Environment.NewLine);
text = text.Replace("</br>", Environment.NewLine);
var dur = DecodeTimeCode(arr[3]);
var start = DecodeTimeCode(arr[2]);
var p = new Paragraph(start, new TimeCode(start.TotalMilliseconds + dur.TotalMilliseconds), text);
subtitle.Paragraphs.Add(p);
if (text.Length > 0 && char.IsDigit(text[0]))
{
_errorCount++;
}
}
else
{
_errorCount += 2;
}
}
foreach (Paragraph p2 in subtitle.Paragraphs)
{
p2.Text = Utilities.AutoBreakLine(p2.Text);
}
subtitle.Renumber();
}
private static TimeCode DecodeTimeCode(string s)
{
var seconds = Convert.ToDouble(s, CultureInfo.InvariantCulture);
return new TimeCode(seconds * 1000.0);
}
}
}