mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 06:52:35 +01:00
Added subtitle format "TMPeg Enc AW5" (with extra newline) - thx Neil :)
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1479 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
bd4f06dba0
commit
a189b21f8b
@ -88,6 +88,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
new TimedText(),
|
||||
new TitleExchangePro(),
|
||||
new TmpegEncText(),
|
||||
new TmpegEncAW5(),
|
||||
new TmpegEncXml(),
|
||||
new TMPlayer(),
|
||||
new TranscriberXml(),
|
||||
|
201
src/Logic/SubtitleFormats/TmpegEncAW5.cs
Normal file
201
src/Logic/SubtitleFormats/TmpegEncAW5.cs
Normal file
@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
class TmpegEncAW5 : TmpegEncXml
|
||||
{
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "TMPGEnc AW5"; }
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
string xmlStructure = @"<?xml version='1.0' encoding='utf-8' ?>
|
||||
<TMPGEncVMESubtitleTextFormat>
|
||||
<Layout>
|
||||
<LayoutItem index='0'>
|
||||
<Name>
|
||||
<![CDATA[Picture bottom layout]]>
|
||||
</Name>
|
||||
<Position>4</Position>
|
||||
<FontName>
|
||||
<![CDATA[Tahoma]]>
|
||||
</FontName>
|
||||
<FontHeight>0.069</FontHeight>
|
||||
<FontColor>17588159451135</FontColor>
|
||||
<FontBold>0</FontBold>
|
||||
<FontItalic>0</FontItalic>
|
||||
<FontUnderline>0</FontUnderline>
|
||||
<FontStrikeOut>0</FontStrikeOut>
|
||||
<HorizonAlign>1</HorizonAlign>
|
||||
<VerticalAlign>2</VerticalAlign>
|
||||
<DirectionVertical>0</DirectionVertical>
|
||||
<BorderActive>1</BorderActive>
|
||||
<BorderSize>0.00345</BorderSize>
|
||||
<BorderColor>0</BorderColor>
|
||||
<TextAlign>1</TextAlign>
|
||||
<DirectionRightToLeft>0</DirectionRightToLeft>
|
||||
</LayoutItem>
|
||||
<LayoutItem index='1'>
|
||||
<Name>
|
||||
<![CDATA[Picture top layout]]>
|
||||
</Name>
|
||||
<Position>4</Position>
|
||||
<FontName>
|
||||
<![CDATA[Tahoma]]>
|
||||
</FontName>
|
||||
<FontHeight>0.1</FontHeight>
|
||||
<FontColor>17588159451135</FontColor>
|
||||
<FontBold>0</FontBold>
|
||||
<FontItalic>0</FontItalic>
|
||||
<FontUnderline>0</FontUnderline>
|
||||
<FontStrikeOut>0</FontStrikeOut>
|
||||
<HorizonAlign>1</HorizonAlign>
|
||||
<VerticalAlign>0</VerticalAlign>
|
||||
<DirectionVertical>0</DirectionVertical>
|
||||
<BorderActive>1</BorderActive>
|
||||
<BorderSize>0.005</BorderSize>
|
||||
<BorderColor>0</BorderColor>
|
||||
<TextAlign>1</TextAlign>
|
||||
<DirectionRightToLeft>0</DirectionRightToLeft>
|
||||
</LayoutItem>
|
||||
<LayoutItem index='2'>
|
||||
<Name>
|
||||
<![CDATA[Picture left layout]]>
|
||||
</Name>
|
||||
<Position>4</Position>
|
||||
<FontName>
|
||||
<![CDATA[Tahoma]]>
|
||||
</FontName>
|
||||
<FontHeight>0.1</FontHeight>
|
||||
<FontColor>17588159451135</FontColor>
|
||||
<FontBold>0</FontBold>
|
||||
<FontItalic>0</FontItalic>
|
||||
<FontUnderline>0</FontUnderline>
|
||||
<FontStrikeOut>0</FontStrikeOut>
|
||||
<HorizonAlign>0</HorizonAlign>
|
||||
<VerticalAlign>1</VerticalAlign>
|
||||
<DirectionVertical>1</DirectionVertical>
|
||||
<BorderActive>1</BorderActive>
|
||||
<BorderSize>0.005</BorderSize>
|
||||
<BorderColor>0</BorderColor>
|
||||
<TextAlign>1</TextAlign>
|
||||
<DirectionRightToLeft>0</DirectionRightToLeft>
|
||||
</LayoutItem>
|
||||
<LayoutItem index='3'>
|
||||
<Name>
|
||||
<![CDATA[Picture right layout]]>
|
||||
</Name>
|
||||
<Position>4</Position>
|
||||
<FontName>
|
||||
<![CDATA[Tahoma]]>
|
||||
</FontName>
|
||||
<FontHeight>0.1</FontHeight>
|
||||
<FontColor>17588159451135</FontColor>
|
||||
<FontBold>0</FontBold>
|
||||
<FontItalic>0</FontItalic>
|
||||
<FontUnderline>0</FontUnderline>
|
||||
<FontStrikeOut>0</FontStrikeOut>
|
||||
<HorizonAlign>2</HorizonAlign>
|
||||
<VerticalAlign>1</VerticalAlign>
|
||||
<DirectionVertical>1</DirectionVertical>
|
||||
<BorderActive>1</BorderActive>
|
||||
<BorderSize>0.005</BorderSize>
|
||||
<BorderColor>0</BorderColor>
|
||||
<TextAlign>1</TextAlign>
|
||||
<DirectionRightToLeft>1</DirectionRightToLeft>
|
||||
</LayoutItem>
|
||||
<LayoutItem index='4'>
|
||||
<Name>
|
||||
<![CDATA[Picture bottom layout]]>
|
||||
</Name>
|
||||
<Position>4</Position>
|
||||
<FontName>
|
||||
<![CDATA[Tahoma]]>
|
||||
</FontName>
|
||||
<FontHeight>0.069</FontHeight>
|
||||
<FontColor>17588159451135</FontColor>
|
||||
<FontBold>0</FontBold>
|
||||
<FontItalic>1</FontItalic>
|
||||
<FontUnderline>0</FontUnderline>
|
||||
<FontStrikeOut>0</FontStrikeOut>
|
||||
<HorizonAlign>1</HorizonAlign>
|
||||
<VerticalAlign>2</VerticalAlign>
|
||||
<DirectionVertical>0</DirectionVertical>
|
||||
<BorderActive>1</BorderActive>
|
||||
<BorderSize>0.00345</BorderSize>
|
||||
<BorderColor>0</BorderColor>
|
||||
<TextAlign>1</TextAlign>
|
||||
<DirectionRightToLeft>0</DirectionRightToLeft>
|
||||
</LayoutItem>
|
||||
</Layout>
|
||||
<Subtitle>
|
||||
</Subtitle>
|
||||
</TMPGEncVMESubtitleTextFormat>".Replace("'", "\"");
|
||||
|
||||
var xml = new XmlDocument();
|
||||
xml.LoadXml(xmlStructure);
|
||||
XmlNode div = xml.DocumentElement.SelectSingleNode("Subtitle");
|
||||
int no = 0;
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
XmlNode paragraph = xml.CreateElement("SubtitleItem");
|
||||
|
||||
string text = Utilities.RemoveHtmlTags(p.Text);
|
||||
paragraph.InnerText = text;
|
||||
paragraph.InnerXml = "<Text><![CDATA[" + paragraph.InnerXml.Replace(Environment.NewLine, "\\n") + "\\n]]></Text>";
|
||||
|
||||
XmlAttribute layoutIndex = xml.CreateAttribute("layoutindex");
|
||||
if (p.Text.Trim().StartsWith("<i>") && p.Text.Trim().EndsWith("</i>"))
|
||||
layoutIndex.InnerText = "4";
|
||||
else
|
||||
layoutIndex.InnerText = "0";
|
||||
|
||||
paragraph.Attributes.Append(layoutIndex);
|
||||
|
||||
XmlAttribute enable = xml.CreateAttribute("enable");
|
||||
enable.InnerText = "1";
|
||||
paragraph.Attributes.Append(enable);
|
||||
|
||||
XmlAttribute start = xml.CreateAttribute("starttime");
|
||||
start.InnerText = p.StartTime.ToString();
|
||||
paragraph.Attributes.Append(start);
|
||||
|
||||
XmlAttribute end = xml.CreateAttribute("endtime");
|
||||
end.InnerText = p.EndTime.ToString();
|
||||
paragraph.Attributes.Append(end);
|
||||
|
||||
div.AppendChild(paragraph);
|
||||
no++;
|
||||
}
|
||||
|
||||
return ToUtf8XmlString(xml);
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
lines.ForEach(line => sb.AppendLine(line));
|
||||
string xmlAsString = sb.ToString().Trim();
|
||||
if ((xmlAsString.Contains("<TMPGEncVMESubtitleTextFormat>") || xmlAsString.Contains("<SubtitleItem ")) && (xmlAsString.Contains("<Subtitle")))
|
||||
{
|
||||
|
||||
var subtitle = new Subtitle();
|
||||
LoadSubtitle(subtitle, lines, fileName);
|
||||
return subtitle.Paragraphs.Count > _errorCount;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
LoadTMpeg(subtitle, lines, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -36,22 +36,15 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var sb = new StringBuilder();
|
||||
lines.ForEach(line => sb.AppendLine(line));
|
||||
string xmlAsString = sb.ToString().Trim();
|
||||
if ((xmlAsString.Contains("<TMPGEncVMESubtitleTextFormat>") || xmlAsString.Contains("<SubtitleItem ")) && (xmlAsString.Contains("<Subtitle")))
|
||||
{
|
||||
var xml = new XmlDocument();
|
||||
try
|
||||
{
|
||||
xml.LoadXml(xmlAsString);
|
||||
var paragraphs = xml.DocumentElement.SelectNodes("Subtitle/SubtitleItem");
|
||||
return paragraphs != null && paragraphs.Count > 0 && xml.DocumentElement.Name == "TMPGEncVMESubtitleTextFormat";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
var subtitle = new Subtitle();
|
||||
LoadSubtitle(subtitle, lines, fileName);
|
||||
return subtitle.Paragraphs.Count > _errorCount;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -221,6 +214,11 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
LoadTMpeg(subtitle, lines, false);
|
||||
}
|
||||
|
||||
internal void LoadTMpeg(Subtitle subtitle, List<string> lines, bool mustHaveLineBreakAsEnd)
|
||||
{
|
||||
_errorCount = 0;
|
||||
double startSeconds = 0;
|
||||
@ -286,7 +284,18 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
endCode = new TimeCode(TimeSpan.FromMilliseconds(startCode.TotalMilliseconds + 3000));
|
||||
}
|
||||
startSeconds = endCode.TotalSeconds;
|
||||
var p = new Paragraph(startCode, endCode, pText.ToString().Trim().Replace("<Text>", string.Empty).Replace("</Text>", string.Empty).Replace("\\n", Environment.NewLine));
|
||||
if (mustHaveLineBreakAsEnd)
|
||||
{
|
||||
if (!pText.ToString().EndsWith("\\n"))
|
||||
_errorCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pText.ToString().EndsWith("\\n"))
|
||||
_errorCount++;
|
||||
}
|
||||
|
||||
var p = new Paragraph(startCode, endCode, pText.ToString().Trim().Replace("<Text>", string.Empty).Replace("</Text>", string.Empty).Replace("\\n", Environment.NewLine).TrimEnd());
|
||||
if (node.Attributes["layoutindex"] != null)
|
||||
{
|
||||
int idx;
|
||||
|
@ -792,6 +792,7 @@
|
||||
<Compile Include="Logic\SubtitleFormats\TitleExchangePro.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\TmpegEncText.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\TmpegEncXml.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\TmpegEncAW5.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\Tmx14.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\TranscriberXml.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\TurboTitler.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user