mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 14:32:35 +01:00
Added new subtitle format (Adobe After Effects ft-ExportMarker) - thx Julian :)
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@2121 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
db373b759e
commit
12d473380d
99
src/Logic/SubtitleFormats/AdobeAfterEffectsFTME.cs
Normal file
99
src/Logic/SubtitleFormats/AdobeAfterEffectsFTME.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
public class AdobeAfterEffectsFTME : SubtitleFormat
|
||||
{
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".xml"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "Adobe After Effects ft-MarkerExporter"; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> 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 = @"
<xml>
<general>
<version>1</version>
</general>
<layers>
<layer name='myLayer' index='1'>
|
||||
</layer>
|
||||
</layers>
|
||||
</xml>".Replace("'", "\"");
|
||||
|
||||
var xml = new XmlDocument();
|
||||
xml.LoadXml(xmlStructure);
|
||||
string innerXml = "<comment value=\"\"/><time value=\"{0}\"/><duration value=\"{1}\"/>";
|
||||
XmlNode root = xml.DocumentElement.SelectSingleNode("layers/layer");
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
XmlNode paragraph = xml.CreateElement("marker");
|
||||
paragraph.InnerXml = string.Format(CultureInfo.InvariantCulture, innerXml, p.StartTime.TotalSeconds, p.Duration.TotalSeconds);
|
||||
paragraph.SelectSingleNode("comment").Attributes["value"].InnerText = p.Text.Replace(Environment.NewLine, "||");
|
||||
root.AppendChild(paragraph);
|
||||
}
|
||||
|
||||
return ToUtf8XmlString(xml);
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
|
||||
var sb = new StringBuilder();
|
||||
lines.ForEach(line => sb.AppendLine(line));
|
||||
|
||||
string allText = sb.ToString();
|
||||
if (!allText.Contains("<layers") && !allText.Contains("<marker>"))
|
||||
return;
|
||||
|
||||
var xml = new XmlDocument();
|
||||
try
|
||||
{
|
||||
xml.LoadXml(allText);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(exception.Message);
|
||||
_errorCount = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (XmlNode node in xml.DocumentElement.SelectNodes("layers/layer/marker"))
|
||||
{
|
||||
try
|
||||
{
|
||||
double start = Convert.ToDouble(node.SelectSingleNode("time").Attributes["value"].InnerText, CultureInfo.InvariantCulture);
|
||||
double end = start + Convert.ToDouble(node.SelectSingleNode("duration").Attributes["value"].InnerText, CultureInfo.InvariantCulture);
|
||||
string text = node.SelectSingleNode("comment").Attributes["value"].InnerText.Replace("||", Environment.NewLine);
|
||||
subtitle.Paragraphs.Add(new Paragraph(text, start * 1000.0, end * 1000.0));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ex.Message);
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
new SubRip(),
|
||||
new AbcIViewer(),
|
||||
new AdobeAfterEffectsFTME(),
|
||||
new AdobeEncore(),
|
||||
new AdobeEncoreLineTabNewLine(),
|
||||
new AdobeEncoreTabs(),
|
||||
|
@ -826,6 +826,7 @@
|
||||
<Compile Include="Logic\SpellCheck\WindowsHunspell.cs" />
|
||||
<Compile Include="Logic\SsaStyle.cs" />
|
||||
<Compile Include="Logic\StripableText.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\AdobeAfterEffectsFTME.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\AdobeEncore.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\AdobeEncoreLineTabNewLine.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\AdobeEncoreLineTabs.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user