From d7664a65e248a9e416df5fec1dd772901df1c656 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Wed, 17 Feb 2016 19:15:18 +0100 Subject: [PATCH] Added new subtitle format --- Changelog.txt | 2 + libse/LibSE.csproj | 1 + libse/SubtitleFormats/SubtitleFormat.cs | 1 + libse/SubtitleFormats/UnknownSubtitle81.cs | 99 ++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 libse/SubtitleFormats/UnknownSubtitle81.cs diff --git a/Changelog.txt b/Changelog.txt index 61f6e3e23..4ddaace89 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -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) diff --git a/libse/LibSE.csproj b/libse/LibSE.csproj index 9f8939176..66bcf27c6 100644 --- a/libse/LibSE.csproj +++ b/libse/LibSE.csproj @@ -361,6 +361,7 @@ + diff --git a/libse/SubtitleFormats/SubtitleFormat.cs b/libse/SubtitleFormats/SubtitleFormat.cs index 2c2160a83..3c512df6e 100644 --- a/libse/SubtitleFormats/SubtitleFormat.cs +++ b/libse/SubtitleFormats/SubtitleFormat.cs @@ -233,6 +233,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats new UnknownSubtitle78(), new UnknownSubtitle79(), new UnknownSubtitle80(), + new UnknownSubtitle81(), }; string path = Configuration.PluginsDirectory; diff --git a/libse/SubtitleFormats/UnknownSubtitle81.cs b/libse/SubtitleFormats/UnknownSubtitle81.cs new file mode 100644 index 000000000..fbb1b2db3 --- /dev/null +++ b/libse/SubtitleFormats/UnknownSubtitle81.cs @@ -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 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 = @" + + +"; + + 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 lines, string fileName) + { + _errorCount = 0; + var sb = new StringBuilder(); + lines.ForEach(line => sb.AppendLine(line)); + var xmlAsText = sb.ToString().Trim(); + if (!xmlAsText.Contains("") || !xmlAsText.Contains("