using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class AbcIViewer : SubtitleFormat
{
public override string Extension => ".xml";
public override string Name => "ABC iView";
public override string ToText(Subtitle subtitle, string title)
{
string xmlStructure =
"" + Environment.NewLine +
"" + Environment.NewLine +
"" + Environment.NewLine +
"" + Environment.NewLine +
"";
var xml = new XmlDocument { XmlResolver = null };
xml.LoadXml(xmlStructure);
XmlNode reel = xml.DocumentElement.SelectSingleNode("reel");
foreach (Paragraph p in subtitle.Paragraphs)
{
XmlNode paragraph = xml.CreateElement("title");
XmlAttribute start = xml.CreateAttribute("start");
start.InnerText = ToTimeCode(p.StartTime.TotalMilliseconds);
paragraph.Attributes.Append(start);
XmlAttribute end = xml.CreateAttribute("end");
end.InnerText = ToTimeCode(p.EndTime.TotalMilliseconds);
paragraph.Attributes.Append(end);
paragraph.InnerText = HtmlUtil.RemoveHtmlTags(p.Text.Replace(Environment.NewLine, "|"), true);
reel.AppendChild(paragraph);
}
return ToUtf8XmlString(xml);
}
private static string ToTimeCode(double totalMilliseconds)
{
var ts = TimeSpan.FromMilliseconds(totalMilliseconds);
return $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}:{ts.Milliseconds:00}";
}
public override void LoadSubtitle(Subtitle subtitle, List lines, string fileName)
{
_errorCount = 0;
bool allTwoCifferMs = true;
var sb = new StringBuilder();
lines.ForEach(line => sb.AppendLine(line));
string xmlString = sb.ToString();
if (!xmlString.Contains("