using System; using System.Collections.Generic; using System.Globalization; using System.Text; using System.Xml; namespace Nikse.SubtitleEdit.Core.SubtitleFormats { public class TimedText : SubtitleFormat { public override string Extension => ".xml"; public override string Name => "Timed Text draft 2006-10"; public override bool IsMine(List lines, string fileName) { var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); string xmlAsString = sb.ToString().RemoveControlCharactersButWhiteSpace().Trim(); if (xmlAsString.Contains("xmlns:tts=\"http://www.w3.org/2006/04")) return false; if (xmlAsString.Contains("http://www.w3.org/") && xmlAsString.Contains("/ttaf1")) { var xml = new XmlDocument { XmlResolver = null }; try { xml.LoadXml(xmlAsString.Replace(" & ", " & ").Replace("Q&A", "Q&A")); var nsmgr = new XmlNamespaceManager(xml.NameTable); nsmgr.AddNamespace("ttaf1", xml.DocumentElement.NamespaceURI); var div = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr).SelectSingleNode("ttaf1:div", nsmgr); if (div == null) div = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr).FirstChild; int numberOfParagraphs = div.ChildNodes.Count; return numberOfParagraphs > 0; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return false; } } return false; } private static string ConvertToTimeString(TimeCode time) { if (Configuration.Settings.SubtitleSettings.TimedText10TimeCodeFormatSource == "hh:mm:ss.ms-two-digits") return $"{time.Hours:00}:{time.Minutes:00}:{time.Seconds:00}.{(int)Math.Round(time.Milliseconds / 10.0):0}"; return $"{time.Hours:00}:{time.Minutes:00}:{time.Seconds:00}.{time.Milliseconds:000}"; } public override string ToText(Subtitle subtitle, string title) { string xmlStructure = "" + Environment.NewLine + "" + Environment.NewLine + " " + Environment.NewLine + " " + Environment.NewLine + " " + Environment.NewLine + " " + Environment.NewLine + " " + Environment.NewLine + "