SubtitleEdit/libse/SubtitleFormats/FinalCutProImage.cs

107 lines
4.3 KiB
C#
Raw Normal View History

2016-02-08 21:11:03 +01:00
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace Nikse.SubtitleEdit.Core.SubtitleFormats
{
public class FinalCutProImage : SubtitleFormat
{
public double FrameRate { get; set; }
public override string Extension => ".xml";
2016-02-08 21:11:03 +01:00
public override string Name => "Final Cut Pro Image";
2016-02-08 21:11:03 +01:00
public override string ToText(Subtitle subtitle, string title)
{
throw new NotImplementedException();
}
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
{
_errorCount = 0;
FrameRate = Configuration.Settings.General.CurrentFrameRate;
var sb = new StringBuilder();
lines.ForEach(line => sb.AppendLine(line));
var xml = new XmlDocument { XmlResolver = null };
try
{
xml.LoadXml(sb.ToString().Trim());
if (xml.DocumentElement.SelectSingleNode("sequence/rate") != null && xml.DocumentElement.SelectSingleNode("sequence/rate/timebase") != null)
{
try
{
var frameRate = double.Parse(xml.DocumentElement.SelectSingleNode("sequence/rate/timebase").InnerText);
if (frameRate > 10 && frameRate < 2000)
{
Configuration.Settings.General.CurrentFrameRate = frameRate;
}
}
catch
{
// ignored
}
}
2016-02-08 21:11:03 +01:00
foreach (XmlNode node in xml.DocumentElement.SelectNodes("sequence/media/video/track/clipitem"))
{
try
{
XmlNode fileNode = node.SelectSingleNode("file");
if (fileNode != null)
{
XmlNode fileNameNode = fileNode.SelectSingleNode("name");
2017-11-03 18:06:39 +01:00
XmlNode pathurlNode = fileNode.SelectSingleNode("pathurl");
2016-02-08 21:11:03 +01:00
if (fileNameNode != null)
{
var p = new Paragraph();
p.Text = fileNameNode.InnerText;
2017-11-03 18:06:39 +01:00
if (pathurlNode != null)
2019-01-19 14:40:37 +01:00
{
2017-11-03 18:06:39 +01:00
p.Extra = pathurlNode.InnerText;
2019-01-19 14:40:37 +01:00
}
2017-11-03 18:06:39 +01:00
2016-02-08 21:11:03 +01:00
XmlNode inNode = node.SelectSingleNode("in");
XmlNode startNode = node.SelectSingleNode("start");
if (startNode != null)
2016-02-08 21:11:03 +01:00
{
p.StartTime.TotalMilliseconds = FramesToMilliseconds(Convert.ToInt32(startNode.InnerText));
2016-02-08 21:11:03 +01:00
}
else if (inNode != null)
2016-02-08 21:11:03 +01:00
{
p.StartTime.TotalMilliseconds = FramesToMilliseconds(Convert.ToInt32(inNode.InnerText));
2016-02-08 21:11:03 +01:00
}
XmlNode outNode = node.SelectSingleNode("out");
XmlNode endNode = node.SelectSingleNode("end");
if (endNode != null)
2016-02-08 21:11:03 +01:00
{
p.EndTime.TotalMilliseconds = FramesToMilliseconds(Convert.ToInt32(endNode.InnerText));
2016-02-08 21:11:03 +01:00
}
else if (outNode != null)
2016-02-08 21:11:03 +01:00
{
p.EndTime.TotalMilliseconds = FramesToMilliseconds(Convert.ToInt32(outNode.InnerText));
2016-02-08 21:11:03 +01:00
}
subtitle.Paragraphs.Add(p);
}
}
}
catch
{
_errorCount++;
}
}
subtitle.Renumber();
}
catch
{
_errorCount = 1;
}
}
}
}