mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Add new sub format - thx thehulk :)
This commit is contained in:
parent
9b95a1a61f
commit
c106a11790
@ -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" />
|
||||
|
@ -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;
|
||||
|
74
libse/SubtitleFormats/UnknownSubtitle90.cs
Normal file
74
libse/SubtitleFormats/UnknownSubtitle90.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user