using System; using System.Collections.Generic; using System.Text; using System.Xml; namespace Nikse.SubtitleEdit.Core.SubtitleFormats { // // //
//

This is fully skinnable through XML
using external images for each button]]>

//

You can put in any order or enable/disable
the control buttons]]>

//

Test below some of the customizable
properties this player has]]>

//

Many other properties related to fonts, sizes, colors
and list properties are in style.css file]]>

//
//
public class FlashXml : SubtitleFormat { public override string Extension => ".xml"; public override string Name => "Flash Xml"; public override bool IsMine(List lines, string fileName) { var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); string xmlAsString = sb.ToString().Trim(); if ((xmlAsString.Contains("") || xmlAsString.Contains(""))) { var xml = new XmlDocument { XmlResolver = null }; try { xml.LoadXml(xmlAsString); var paragraphs = xml.DocumentElement.SelectNodes("div/p"); return paragraphs != null && paragraphs.Count > 0 && xml.DocumentElement.Name == "tt"; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } return false; } private static string ConvertToTimeString(TimeCode time) { return string.Format("{0:00}:{1:00}:{2:00}.{3:00}", time.Hours, time.Minutes, time.Seconds, time.Milliseconds); } public override string ToText(Subtitle subtitle, string title) { string xmlStructure = "" + Environment.NewLine + "" + Environment.NewLine + "
" + Environment.NewLine + "
" + Environment.NewLine + "
"; var xml = new XmlDocument(); xml.LoadXml(xmlStructure); XmlNode div = xml.DocumentElement.SelectSingleNode("div"); foreach (Paragraph p in subtitle.Paragraphs) { XmlNode paragraph = xml.CreateElement("p"); string text = HtmlUtil.RemoveHtmlTags(p.Text, true); paragraph.InnerText = text; paragraph.InnerXml = "" + paragraph.InnerXml.Replace(Environment.NewLine, "
") + "]]>"; XmlAttribute start = xml.CreateAttribute("begin"); start.InnerText = ConvertToTimeString(p.StartTime); paragraph.Attributes.Append(start); XmlAttribute end = xml.CreateAttribute("end"); end.InnerText = ConvertToTimeString(p.EndTime); paragraph.Attributes.Append(end); div.AppendChild(paragraph); } return ToUtf8XmlString(xml); } public override void LoadSubtitle(Subtitle subtitle, List lines, string fileName) { _errorCount = 0; double startSeconds = 0; var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); var xml = new XmlDocument { XmlResolver = null }; xml.LoadXml(sb.ToString().Trim()); var pText = new StringBuilder(); foreach (XmlNode node in xml.DocumentElement.SelectNodes("div/p")) { try { foreach (XmlNode innerNode in node.ChildNodes) { switch (innerNode.Name) { case "br": pText.AppendLine(); break; default: pText.Append(innerNode.InnerText.Trim()); break; } } var start = string.Empty; if (node.Attributes["begin"] != null) { start = node.Attributes["begin"].InnerText; } var end = string.Empty; if (node.Attributes["end"] != null) { end = node.Attributes["end"].InnerText; } var dur = string.Empty; if (node.Attributes["dur"] != null) { dur = node.Attributes["dur"].InnerText; } TimeCode startCode = TimeCode.FromSeconds(startSeconds); if (start.Length > 0) { startCode = GetTimeCode(start); } TimeCode endCode; if (end.Length > 0) { endCode = GetTimeCode(end); } else if (dur.Length > 0) { endCode = new TimeCode(GetTimeCode(dur).TotalMilliseconds + startCode.TotalMilliseconds); } else { endCode = new TimeCode(startCode.TotalMilliseconds + 3000); } startSeconds = endCode.TotalSeconds; subtitle.Paragraphs.Add(new Paragraph(startCode, endCode, pText.ToString().Replace("", string.Empty).Replace("", string.Empty))); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _errorCount++; } pText.Clear(); } subtitle.Renumber(); } private static TimeCode GetTimeCode(string s) { if (s.EndsWith('s')) { s = s.TrimEnd('s'); return TimeCode.FromSeconds(double.Parse(s)); } var parts = s.Split(new[] { ':', '.', ',' }); return new TimeCode(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3])); } } }