mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-23 19:52:48 +01:00
Add new subtitle format
This commit is contained in:
parent
723dab6365
commit
bffcc16fbb
@ -203,6 +203,7 @@
|
||||
<Compile Include="SubtitleFormats\JsonType15.cs" />
|
||||
<Compile Include="SubtitleFormats\KaraokeCdgCreatorText.cs" />
|
||||
<Compile Include="SubtitleFormats\GooglePlayJson.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle92.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle89.cs" />
|
||||
<Compile Include="SubtitleFormats\OtterAi.cs" />
|
||||
<Compile Include="SubtitleFormats\OgmChapters.cs" />
|
||||
|
@ -283,7 +283,8 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
new UnknownSubtitle88(),
|
||||
new UnknownSubtitle89(),
|
||||
new UnknownSubtitle90(),
|
||||
new UnknownSubtitle91()
|
||||
new UnknownSubtitle91(),
|
||||
new UnknownSubtitle92()
|
||||
};
|
||||
|
||||
string path = Configuration.PluginsDirectory;
|
||||
|
92
libse/SubtitleFormats/UnknownSubtitle92.cs
Normal file
92
libse/SubtitleFormats/UnknownSubtitle92.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
public class UnknownSubtitle92 : SubtitleFormat
|
||||
{
|
||||
public override string Extension => ".xml";
|
||||
|
||||
public override string Name => "Unknown 92";
|
||||
|
||||
private static string ToTimeCode(TimeCode tc)
|
||||
{
|
||||
return tc.TotalMilliseconds.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
private static TimeCode DecodeTimeCode(string s)
|
||||
{
|
||||
return new TimeCode(long.Parse(s));
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
var xml = new XmlDocument();
|
||||
xml.LoadXml("<xml></xml>");
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
XmlNode paragraph = xml.CreateElement("dia");
|
||||
|
||||
var cData = xml.CreateCDataSection(HtmlUtil.RemoveHtmlTags(p.Text));
|
||||
XmlNode text = xml.CreateElement("sub");
|
||||
text.AppendChild(cData);
|
||||
paragraph.AppendChild(text);
|
||||
|
||||
XmlNode start = xml.CreateElement("st");
|
||||
start.InnerText = ToTimeCode(p.StartTime);
|
||||
paragraph.AppendChild(start);
|
||||
|
||||
XmlNode duration = xml.CreateElement("et");
|
||||
duration.InnerText = ToTimeCode(p.EndTime);
|
||||
paragraph.AppendChild(duration);
|
||||
|
||||
xml.DocumentElement.AppendChild(paragraph);
|
||||
}
|
||||
|
||||
return ToUtf8XmlString(xml);
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
var sb = new StringBuilder();
|
||||
lines.ForEach(line => sb.AppendLine(line));
|
||||
string allText = sb.ToString();
|
||||
if (!allText.Contains("</dia>") || !allText.Contains("</sub>"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var xml = new XmlDocument { XmlResolver = null };
|
||||
try
|
||||
{
|
||||
xml.LoadXml(allText);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_errorCount = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (XmlNode node in xml.DocumentElement.SelectNodes("dia"))
|
||||
{
|
||||
try
|
||||
{
|
||||
string text = node.SelectSingleNode("sub").InnerText;
|
||||
string start = node.SelectSingleNode("st").InnerText;
|
||||
string end = node.SelectSingleNode("et").InnerText;
|
||||
subtitle.Paragraphs.Add(new Paragraph(DecodeTimeCode(start), DecodeTimeCode(end), text));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ex.Message);
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
subtitle.Renumber();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user