mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 12:44:46 +01:00
Added new subtitle format
This commit is contained in:
parent
d95671ca9b
commit
d7664a65e2
@ -2,6 +2,7 @@
|
||||
|
||||
3.4.12 (xth March 2016) BETA
|
||||
* NEW:
|
||||
* Added new subtitle formats
|
||||
* Norwegian translation - thx Imre
|
||||
* IMPROVED:
|
||||
* Updated Catalan translation - thx juansa
|
||||
@ -25,6 +26,7 @@
|
||||
* Allow reading of small PAC files - thx Mike
|
||||
* Fixed bug in "Fix invalid italic tags" - thx ivandrofly
|
||||
* Fixed allowing random order of json tags - thx fela98
|
||||
* Remember (extra) inline styles for TTML 1.0 - thx Oskar
|
||||
|
||||
|
||||
3.4.11 (16th January 2016)
|
||||
|
@ -361,6 +361,7 @@
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle29.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle3.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle30.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle81.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle80.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle79.cs" />
|
||||
<Compile Include="SubtitleFormats\UnknownSubtitle31.cs" />
|
||||
|
@ -233,6 +233,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
new UnknownSubtitle78(),
|
||||
new UnknownSubtitle79(),
|
||||
new UnknownSubtitle80(),
|
||||
new UnknownSubtitle81(),
|
||||
};
|
||||
|
||||
string path = Configuration.PluginsDirectory;
|
||||
|
99
libse/SubtitleFormats/UnknownSubtitle81.cs
Normal file
99
libse/SubtitleFormats/UnknownSubtitle81.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
{
|
||||
internal class UnknownSubtitle81 : SubtitleFormat
|
||||
{
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".xml"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "Unknown 81"; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
var subtitle = new Subtitle();
|
||||
LoadSubtitle(subtitle, lines, fileName);
|
||||
return subtitle.Paragraphs.Count > _errorCount;
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
const string xmpTemplate = @"<?xml version='1.0' encoding='utf-8'?>
|
||||
<timedtext format='3'>
|
||||
<body />
|
||||
</timedtext>";
|
||||
|
||||
var xml = new XmlDocument();
|
||||
xml.LoadXml(xmpTemplate.Replace('\'', '"'));
|
||||
var paragraphInsertNode = xml.DocumentElement.SelectSingleNode("body");
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
XmlNode paragraph = xml.CreateElement("p");
|
||||
paragraph.InnerText = p.Text.Replace(Environment.NewLine, " ");
|
||||
|
||||
XmlAttribute tAttribute = xml.CreateAttribute("t");
|
||||
tAttribute.InnerText = Convert.ToInt64(p.StartTime.TotalMilliseconds).ToString();
|
||||
paragraph.Attributes.Append(tAttribute);
|
||||
|
||||
XmlAttribute dAttribute = xml.CreateAttribute("d");
|
||||
dAttribute.InnerText = Convert.ToInt64(p.Duration.TotalMilliseconds).ToString();
|
||||
paragraph.Attributes.Append(dAttribute);
|
||||
|
||||
paragraphInsertNode.AppendChild(paragraph);
|
||||
}
|
||||
return ToUtf8XmlString(xml).Replace(" xmlns=\"\"", string.Empty);
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
var sb = new StringBuilder();
|
||||
lines.ForEach(line => sb.AppendLine(line));
|
||||
var xmlAsText = sb.ToString().Trim();
|
||||
if (!xmlAsText.Contains("</timedtext>") || !xmlAsText.Contains("<p "))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var xml = new XmlDocument { XmlResolver = null };
|
||||
xml.LoadXml(xmlAsText);
|
||||
foreach (XmlNode node in xml.DocumentElement.SelectNodes("body/p"))
|
||||
{
|
||||
try
|
||||
{
|
||||
var timeCodeIn = new TimeCode(Convert.ToDouble(node.Attributes["t"].InnerText));
|
||||
var timeCodeOut = new TimeCode(timeCodeIn.TotalMilliseconds + Convert.ToDouble(node.Attributes["d"].InnerText));
|
||||
var p = new Paragraph(timeCodeIn, timeCodeOut, Utilities.AutoBreakLine(node.InnerText));
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ex.Message);
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
subtitle.Renumber();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user