using System; using System.Collections.Generic; using System.Text; using System.Xml; namespace Nikse.SubtitleEdit.Core.SubtitleFormats { public class UTSubtitleXml : SubtitleFormat { public override string Extension { get { return ".xml"; } } public override string Name { get { return "UT Subtitle xml"; } } 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 > 0; } public override string ToText(Subtitle subtitle, string title) { string xmlStructure = "" + Environment.NewLine + "" + Environment.NewLine + ""; var xml = new XmlDocument(); xml.LoadXml(xmlStructure); XmlNode root = xml.DocumentElement; foreach (Paragraph p in subtitle.Paragraphs) { // // u drugi dio naše emisije]]> // XmlNode ut = xml.CreateElement("ut"); XmlAttribute et = xml.CreateAttribute("secOut"); et.InnerText = string.Format("{0:0.0##}", p.EndTime.TotalSeconds).Replace(",", "."); ut.Attributes.Append(et); XmlAttribute st = xml.CreateAttribute("secIn"); st.InnerText = string.Format("{0:0.0##}", p.StartTime.TotalSeconds).Replace(",", "."); ut.Attributes.Append(st); ut.InnerText = p.Text; ut.InnerXml = "") + "]]>"; root.AppendChild(ut); } return ToUtf8XmlString(xml); } public override void LoadSubtitle(Subtitle subtitle, List lines, string fileName) { _errorCount = 0; var sb = new StringBuilder(); lines.ForEach(line => sb.AppendLine(line)); if (!sb.ToString().Contains("", Environment.NewLine).Replace("
", Environment.NewLine); var p = new Paragraph(); p.StartTime.TotalSeconds = Convert.ToDouble(startTime, System.Globalization.CultureInfo.InvariantCulture); p.EndTime.TotalSeconds = Convert.ToDouble(endTime, System.Globalization.CultureInfo.InvariantCulture); p.Text = text; subtitle.Paragraphs.Add(p); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _errorCount++; } } subtitle.Renumber(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); _errorCount = 1; return; } } } }