mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 19:22:53 +01:00
Working on formats
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@373 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
6bcd1d2c6a
commit
6794c60843
282
src/Logic/SubtitleFormats/DCSubtitle.cs
Normal file
282
src/Logic/SubtitleFormats/DCSubtitle.cs
Normal file
@ -0,0 +1,282 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
|
||||
//<DCSubtitle Version="1.0">
|
||||
//<!-- *** www.digital-cinema-services.de *** -->
|
||||
//<!-- *** ElMariKonverter *** -->
|
||||
//<Id>urn:uuid:0b8a1af2-2073-493c-aea1-fa6b5601101a</Id>
|
||||
//<MovieTitle>Im Himmel unter der Erde</MovieTitle>
|
||||
//<ContentTitleText>de - Im Himmel unter der Erde</ContentTitleText>
|
||||
//<AnnotationText>de - Im Himmel unter der Erde</AnnotationText>
|
||||
//<IssueDate>2011-03-25T14:07:00</IssueDate>
|
||||
//<StartTime>00:00:00:000</StartTime>
|
||||
//<ReelNumber>1</ReelNumber>
|
||||
//<Language>de</Language>
|
||||
//<EditRate>24 1</EditRate>
|
||||
//<TimeCodeRate>24</TimeCodeRate>
|
||||
//<LoadFont Id="Font1" URI="Arial.ttf"/>
|
||||
//<SubtitleList>
|
||||
//<Font Id="Font1" Color="FFFFFFFF" Effect="outline" EffectColor="FF000000" Italic="no" Underlined="no" Script="normal" Size="52">
|
||||
//<Subtitle SpotNumber="1" FadeUpTime="20" FadeDownTime="20" TimeIn="00:50:05:10" TimeOut="00:50:10:01">
|
||||
//<Text Direction="horizontal" HAlign="center" HPosition="0" VAlign="bottom" VPosition="8"><Font Italic="yes">Meine Mutter und meine Schwester,</Font></Text>
|
||||
//</Subtitle>
|
||||
|
||||
class DCSubtitle : SubtitleFormat
|
||||
{
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".xml"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "DCSubtitle"; }
|
||||
}
|
||||
|
||||
public override bool HasLineNumber
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMine(List<string> lines, string fileName)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
lines.ForEach(line => sb.AppendLine(line));
|
||||
string xmlAsString = sb.ToString().Trim();
|
||||
if (xmlAsString.Contains("<DCSubtitle") &&
|
||||
xmlAsString.Contains("<SubtitleList"))
|
||||
{
|
||||
XmlDocument xml = new XmlDocument();
|
||||
try
|
||||
{
|
||||
xml.LoadXml(xmlAsString);
|
||||
|
||||
XmlNode subtitleList = xml.DocumentElement.SelectSingleNode("SubtitleList");
|
||||
if (subtitleList != null)
|
||||
{
|
||||
var subtitles = subtitleList.SelectNodes("//Subtitle");
|
||||
return subtitles != null && subtitles.Count > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string s = ex.Message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string ConvertToTimeString(TimeCode time)
|
||||
{
|
||||
return string.Format("{0:00}:{1:00}:{2:00}.{3:00}", time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
string xmlStructure = "<DCSubtitle Version=\"1.0\">" +
|
||||
@" <Id>urn:uuid:0b8a1af2-2073-493c-aea1-fa6b5601101a</Id>
|
||||
<MovieTitle>[TITLE]</MovieTitle>
|
||||
<ContentTitleText>[TITLE]</ContentTitleText>
|
||||
<AnnotationText>[TITLE]</AnnotationText>
|
||||
<IssueDate>[DATE]</IssueDate>
|
||||
<StartTime>00:00:00:000</StartTime>
|
||||
<ReelNumber>1</ReelNumber>
|
||||
<Language>de</Language>
|
||||
<EditRate>24 1</EditRate>
|
||||
<TimeCodeRate>24</TimeCodeRate>
|
||||
<LoadFont Id=" + "\"Font1\" URI=\"Arial.ttf\"/>" + Environment.NewLine +
|
||||
" <SubtitleList>" + Environment.NewLine +
|
||||
" <Font Id=\"Font1\" Color=\"FFFFFFFF\" Effect=\"outline\" EffectColor=\"FF000000\" Italic=\"no\" Underlined=\"no\" Script=\"normal\" Size=\"52\">" + Environment.NewLine +
|
||||
" </Font>" + Environment.NewLine +
|
||||
" </SubtitleList>" + Environment.NewLine +
|
||||
"</DCSubtitle>";
|
||||
XmlNode t = new XmlDocument().CreateElement("title");
|
||||
t.InnerText = title;
|
||||
xmlStructure = xmlStructure.Replace("[TITLE]", t.InnerXml);
|
||||
xmlStructure = xmlStructure.Replace("[DATE]", string.Format("{0:0000}:{1:00}:{2:00}T{3:HH:mm:ss}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now)); //2011-03-25T14:07:00
|
||||
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.LoadXml(xmlStructure);
|
||||
|
||||
XmlNode mainListFont = xml.DocumentElement.SelectSingleNode("//SubtitleList/Font");
|
||||
int no = 0;
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
//<Subtitle SpotNumber="1" FadeUpTime="20" FadeDownTime="20" TimeIn="00:50:05:10" TimeOut="00:50:10:01">
|
||||
//<Text Direction="horizontal" HAlign="center" HPosition="0" VAlign="bottom" VPosition="8"><Font Italic="yes">Meine Mutter und meine Schwester,</Font></Text>
|
||||
//</Subtitle>
|
||||
XmlNode subNode = xml.CreateElement("Subtitle");
|
||||
|
||||
XmlAttribute end = xml.CreateAttribute("TimeOut");
|
||||
end.InnerText = ConvertToTimeString(p.EndTime);
|
||||
subNode.Attributes.Append(end);
|
||||
|
||||
XmlAttribute start = xml.CreateAttribute("TimeIn");
|
||||
start.InnerText = ConvertToTimeString(p.StartTime);
|
||||
subNode.Attributes.Append(start);
|
||||
|
||||
XmlAttribute fadeDownTime = xml.CreateAttribute("FadeDownTime");
|
||||
fadeDownTime.InnerText = "20";
|
||||
subNode.Attributes.Append(fadeDownTime);
|
||||
|
||||
XmlAttribute fadeUpTime = xml.CreateAttribute("FadeUpTime");
|
||||
fadeUpTime.InnerText = "20";
|
||||
subNode.Attributes.Append(fadeUpTime);
|
||||
|
||||
XmlAttribute id = xml.CreateAttribute("SpotNumber");
|
||||
id.InnerText = no.ToString();
|
||||
subNode.Attributes.Append(id);
|
||||
|
||||
// <Text VPosition="8" VAlign="bottom" HPosition="0" HAlign="center" Direction="horizontal">Er hat uns allen geholfen:</Text>
|
||||
string[] lines = p.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
int vPos = 8;
|
||||
foreach (string line in lines)
|
||||
{
|
||||
XmlNode textNode = xml.CreateElement("Text");
|
||||
|
||||
XmlAttribute vPosition = xml.CreateAttribute("VPosition");
|
||||
vPosition.InnerText = vPos.ToString();
|
||||
textNode.Attributes.Append(vPosition);
|
||||
|
||||
XmlAttribute vAlign = xml.CreateAttribute("VAlign");
|
||||
vAlign.InnerText = "bottom";
|
||||
textNode.Attributes.Append(vAlign);
|
||||
|
||||
XmlAttribute hAlign = xml.CreateAttribute("HAlign");
|
||||
hAlign.InnerText = "center";
|
||||
textNode.Attributes.Append(hAlign);
|
||||
|
||||
XmlAttribute direction = xml.CreateAttribute("Direction");
|
||||
direction.InnerText = "horizontal";
|
||||
textNode.Attributes.Append(direction);
|
||||
|
||||
if (line.StartsWith("<i>"))
|
||||
{
|
||||
XmlNode fontNode = xml.CreateElement("Font");
|
||||
|
||||
XmlAttribute italic = xml.CreateAttribute("Italic");
|
||||
italic.InnerText = "yes";
|
||||
fontNode.Attributes.Append(italic);
|
||||
|
||||
fontNode.InnerText = Utilities.RemoveHtmlTags(line);
|
||||
textNode.AppendChild(fontNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
textNode.InnerText = Utilities.RemoveHtmlTags(line);
|
||||
}
|
||||
|
||||
subNode.AppendChild(textNode);
|
||||
vPos += 7;
|
||||
}
|
||||
|
||||
mainListFont.AppendChild(subNode);
|
||||
no++;
|
||||
}
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
XmlTextWriter writer = new XmlTextWriter(ms, Encoding.UTF8);
|
||||
writer.Formatting = Formatting.Indented;
|
||||
xml.Save(writer);
|
||||
return Encoding.UTF8.GetString(ms.ToArray()).Trim();
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
lines.ForEach(line => sb.AppendLine(line));
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.LoadXml(sb.ToString());
|
||||
|
||||
XmlNode subtitleList = xml.DocumentElement.SelectSingleNode("SubtitleList");
|
||||
foreach (XmlNode node in subtitleList.SelectNodes("//Subtitle"))
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder pText = new StringBuilder();
|
||||
string lastVPosition = string.Empty;
|
||||
foreach (XmlNode innerNode in node.ChildNodes)
|
||||
{
|
||||
switch (innerNode.Name.ToString())
|
||||
{
|
||||
case "br":
|
||||
pText.AppendLine();
|
||||
break;
|
||||
case "Text":
|
||||
if (innerNode.Attributes["VPosition"] != null)
|
||||
{
|
||||
string vPosition = innerNode.Attributes["VPosition"].InnerText;
|
||||
if (vPosition != lastVPosition)
|
||||
{
|
||||
if (pText.Length > 0 && lastVPosition != string.Empty)
|
||||
pText.AppendLine();
|
||||
lastVPosition = vPosition;
|
||||
}
|
||||
}
|
||||
if (innerNode.ChildNodes.Count == 0)
|
||||
{
|
||||
pText.Append(innerNode.InnerText);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (XmlNode innerInnerNode in innerNode)
|
||||
{
|
||||
if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Italic"] != null &&
|
||||
innerInnerNode.Attributes["Italic"].InnerText.ToLower() == "yes")
|
||||
{
|
||||
pText.Append("<i>" + innerNode.InnerText + "</i>");
|
||||
}
|
||||
else
|
||||
{
|
||||
pText.Append(innerNode.InnerText);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
pText.Append(innerNode.InnerText);
|
||||
break;
|
||||
}
|
||||
}
|
||||
string start = node.Attributes["TimeIn"].InnerText;
|
||||
string end = node.Attributes["TimeOut"].InnerText;
|
||||
|
||||
subtitle.Paragraphs.Add(new Paragraph(GetTimeCode(start), GetTimeCode(end), pText.ToString()));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string s = ex.Message;
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
|
||||
private static TimeCode GetTimeCode(string s)
|
||||
{
|
||||
string[] parts = s.Split(new char[] { ':', '.', ',' });
|
||||
TimeSpan ts = new TimeSpan(0, int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3]));
|
||||
return new TimeCode(ts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -847,7 +847,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
for (int i = 0; i < 112; i++) // skip fist byte (seems to be always 0xd/32/space - thx Iban)
|
||||
{
|
||||
byte b = buffer[index + 16 + i];
|
||||
if (i == 0 || (i == 2 && b <= 0xf) || (i == 3 && b <= 0xf))
|
||||
if (b <= 0xf && (i == 0 || i == 2 || i == 3))
|
||||
{
|
||||
// not used, 0=0xd, 2=0xb, 3=0xb
|
||||
}
|
||||
|
578
src/Logic/SubtitleFormats/FinalCutProTextXml.cs
Normal file
578
src/Logic/SubtitleFormats/FinalCutProTextXml.cs
Normal file
@ -0,0 +1,578 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
class FinalCutProTestXml : SubtitleFormat
|
||||
{
|
||||
public double FrameRate { get; set; }
|
||||
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".xml"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "Final Cut Pro Test Xml"; }
|
||||
}
|
||||
|
||||
public override bool HasLineNumber
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private string IsNtsc()
|
||||
{
|
||||
if (FrameRate >= 29.976 && FrameRate <= 30.0)
|
||||
return "TRUE";
|
||||
return "FALSE";
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
if (Configuration.Settings.General.DefaultFrameRate > 26)
|
||||
FrameRate = 30;
|
||||
else
|
||||
FrameRate = 25;
|
||||
|
||||
string xmlStructure =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine +
|
||||
"<!DOCTYPE xmeml>" + Environment.NewLine +
|
||||
"<xmeml version=\"3\">" + Environment.NewLine +
|
||||
" <sequence id=\"Subtitles\">" + Environment.NewLine +
|
||||
" <name>Subtitles</name>" + Environment.NewLine +
|
||||
" <media>" + Environment.NewLine +
|
||||
" <video />" + Environment.NewLine +
|
||||
" </media>" + Environment.NewLine +
|
||||
" </sequence>" + Environment.NewLine +
|
||||
"</xmeml>";
|
||||
|
||||
string xmlTrackStructure =
|
||||
"<generatoritem>" + Environment.NewLine +
|
||||
" <name>Text</name>" + Environment.NewLine +
|
||||
" <rate>" + Environment.NewLine +
|
||||
" <ntsc>" + IsNtsc() + "</ntsc>" + Environment.NewLine +
|
||||
" <timebase>" + (int)Math.Round(FrameRate) + "</timebase>" + Environment.NewLine +
|
||||
" </rate>" + Environment.NewLine +
|
||||
" <start></start>" + Environment.NewLine + // start frame?
|
||||
" <end></end>" + Environment.NewLine + // end frame?
|
||||
" <enabled>TRUE</enabled>" + Environment.NewLine +
|
||||
" <anamorphic>FALSE</anamorphic>" + Environment.NewLine +
|
||||
" <alphatype>black</alphatype>" + Environment.NewLine +
|
||||
" <effect id=\"subtitle\">" + Environment.NewLine +
|
||||
" <name>Text</name>" + Environment.NewLine +
|
||||
// " <effectid>Text</effectid>" + Environment.NewLine +
|
||||
" <effectcategory>Text</effectcategory>" + Environment.NewLine +
|
||||
" <effecttype>generator</effecttype>" + Environment.NewLine +
|
||||
" <mediatype>video</mediatype>" + Environment.NewLine +
|
||||
" <parameter>" + Environment.NewLine +
|
||||
" <parameterid>str</parameterid>" + Environment.NewLine +
|
||||
" <name>Text</name>" + Environment.NewLine +
|
||||
" <value />" + Environment.NewLine + // TEXT GOES HERE
|
||||
" </parameter>" + Environment.NewLine +
|
||||
" </effect>" + Environment.NewLine +
|
||||
"</generatoritem>";
|
||||
|
||||
string xmlTrackStructure2 =
|
||||
@"<generatoritem id='Subtitle Edit'>
|
||||
<name>edit 'B subtitle</name>
|
||||
<duration>3000</duration>
|
||||
<rate>
|
||||
<ntsc>FALSE</ntsc>
|
||||
<timebase>25</timebase>
|
||||
</rate>
|
||||
<in>1375</in>
|
||||
<out>1383</out>
|
||||
<start>0</start>
|
||||
<end>8</end>
|
||||
<enabled>TRUE</enabled>
|
||||
<anamorphic>TRUE</anamorphic>
|
||||
<alphatype>black</alphatype>
|
||||
<logginginfo>
|
||||
<scene>
|
||||
</scene>
|
||||
<shottake>
|
||||
</shottake>
|
||||
<lognote>
|
||||
</lognote>
|
||||
<good>FALSE</good>
|
||||
</logginginfo>
|
||||
<labels>
|
||||
<label2>
|
||||
</label2>
|
||||
</labels>
|
||||
<comments>
|
||||
<mastercomment1>
|
||||
</mastercomment1>
|
||||
<mastercomment2>
|
||||
</mastercomment2>
|
||||
<mastercomment3>
|
||||
</mastercomment3>
|
||||
<mastercomment4>
|
||||
</mastercomment4>
|
||||
</comments>
|
||||
<effect>
|
||||
<name>edit 'B subtitle</name>
|
||||
<effectid>edit 'B subtitle</effectid>
|
||||
<effectcategory>Text</effectcategory>
|
||||
<effecttype>generator</effecttype>
|
||||
<mediatype>video</mediatype>
|
||||
<parameter>
|
||||
<parameterid>part1</parameterid>
|
||||
<name>Text Settings</name>
|
||||
<value>0</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>str</parameterid>
|
||||
<name>Text</name>
|
||||
<value></value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontname</parameterid>
|
||||
<name>Font</name>
|
||||
<value>Arial Narrow</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontstyle</parameterid>
|
||||
<name>Style</name>
|
||||
<valuemin>1</valuemin>
|
||||
<valuemax>4</valuemax>
|
||||
<valuelist>
|
||||
<valueentry>
|
||||
<name>Plain</name>
|
||||
<value>1</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Bold</name>
|
||||
<value>2</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Italic</name>
|
||||
<value>3</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Bold/Italic</name>
|
||||
<value>4</value>
|
||||
</valueentry>
|
||||
</valuelist>
|
||||
<value>1</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontalign</parameterid>
|
||||
<name>Alignment</name>
|
||||
<valuemin>1</valuemin>
|
||||
<valuemax>3</valuemax>
|
||||
<valuelist>
|
||||
<valueentry>
|
||||
<name>Left</name>
|
||||
<value>1</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Center</name>
|
||||
<value>2</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Right</name>
|
||||
<value>3</value>
|
||||
</valueentry>
|
||||
</valuelist>
|
||||
<value>2</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontsize</parameterid>
|
||||
<name>Size</name>
|
||||
<valuemin>20</valuemin>
|
||||
<valuemax>80</valuemax>
|
||||
<value>28</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>origin</parameterid>
|
||||
<name>Origin</name>
|
||||
<value>
|
||||
<horiz>0</horiz>
|
||||
<vert>0.3056</vert>
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>aspect</parameterid>
|
||||
<name>Aspect</name>
|
||||
<valuemin>0</valuemin>
|
||||
<valuemax>2</valuemax>
|
||||
<value>1</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>textopacity</parameterid>
|
||||
<name>Text Opacity</name>
|
||||
<valuemin>0</valuemin>
|
||||
<valuemax>100</valuemax>
|
||||
<value>100</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>textcolor</parameterid>
|
||||
<name>Text Color</name>
|
||||
<value>
|
||||
<alpha>255</alpha>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fonttrack</parameterid>
|
||||
<name>Tracking</name>
|
||||
<valuemin>0</valuemin>
|
||||
<valuemax>10</valuemax>
|
||||
<value>1</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>leading</parameterid>
|
||||
<name>Leading</name>
|
||||
<valuemin>-40</valuemin>
|
||||
<valuemax>40</valuemax>
|
||||
<value>-13</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>autokern</parameterid>
|
||||
<name>Auto Kerning</name>
|
||||
<value>TRUE</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>part2</parameterid>
|
||||
<name>Outline Settings</name>
|
||||
<value>0</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>linewidth</parameterid>
|
||||
<name>Width</name>
|
||||
<valuemin>0</valuemin>
|
||||
<valuemax>50</valuemax>
|
||||
<value>8</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>linesoft</parameterid>
|
||||
<name>Soft</name>
|
||||
<valuemin>0</valuemin>
|
||||
<valuemax>100</valuemax>
|
||||
<value>38</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>linecolor</parameterid>
|
||||
<name>Color</name>
|
||||
<value>
|
||||
<alpha>255</alpha>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>part3</parameterid>
|
||||
<name>Shadow Settings</name>
|
||||
<value>0</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>shadowoffsetx</parameterid>
|
||||
<name>Offset X</name>
|
||||
<valuemin>-20</valuemin>
|
||||
<valuemax>20</valuemax>
|
||||
<value>3</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>shadowoffsety</parameterid>
|
||||
<name>Offset y</name>
|
||||
<valuemin>-20</valuemin>
|
||||
<valuemax>20</valuemax>
|
||||
<value>3</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>shadowopacity</parameterid>
|
||||
<name>Opacity</name>
|
||||
<valuemin>0</valuemin>
|
||||
<valuemax>100</valuemax>
|
||||
<value>75</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>shadowsoft</parameterid>
|
||||
<name>Softness</name>
|
||||
<valuemin>0</valuemin>
|
||||
<valuemax>100</valuemax>
|
||||
<value>2</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>shadowcolor</parameterid>
|
||||
<name>Color</name>
|
||||
<value>
|
||||
<alpha>255</alpha>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</value>
|
||||
</parameter>
|
||||
</effect>
|
||||
<sourcetrack>
|
||||
<mediatype>video</mediatype>
|
||||
</sourcetrack>
|
||||
</generatoritem>";
|
||||
|
||||
string xmlTrackStructure3a =
|
||||
@"<generatoritem>
|
||||
<name>Text</name>
|
||||
<duration>3600</duration>
|
||||
<rate>
|
||||
<ntsc>TRUE</ntsc>
|
||||
<timebase>30</timebase>
|
||||
</rate>
|
||||
<in>1650</in>
|
||||
<out>1784</out>
|
||||
<start>0</start>
|
||||
<end>134</end>
|
||||
<enabled>TRUE</enabled>
|
||||
<anamorphic>FALSE</anamorphic>
|
||||
<alphatype>black</alphatype>
|
||||
<effect id = 'subtitle'>
|
||||
<name>Text</name>
|
||||
<effectid>Text</effectid>
|
||||
<effectcategory>Text</effectcategory>
|
||||
<effecttype>generator</effecttype>
|
||||
<mediatype>video</mediatype>
|
||||
<parameter>
|
||||
<parameterid>str</parameterid>
|
||||
<name>Text</name>
|
||||
<value>If you look at the Lindy Hop you'll see a couple just moving</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontname</parameterid>
|
||||
<name>Font</name>
|
||||
<value>Futura</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontsize</parameterid>
|
||||
<name>Size</name>
|
||||
<valuemin>0</valuemin>
|
||||
<valuemax>1000</valuemax>
|
||||
<value>36</value></parameter>
|
||||
<parameter>
|
||||
<parameterid>fontstyle</parameterid>
|
||||
<name>Style</name>
|
||||
<valuemin>1</valuemin>
|
||||
<valuemax>4</valuemax>
|
||||
<valuelist>
|
||||
<valueentry>
|
||||
<name>Plain</name>
|
||||
<value>1</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Bold</name>
|
||||
<value>2</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Italic</name>
|
||||
<value>3</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Bold/Italic</name>
|
||||
<value>4</value>
|
||||
</valueentry>
|
||||
</valuelist>
|
||||
<value>3</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontalign</parameterid>
|
||||
<name>Alignment</name>
|
||||
<valuemin>1</valuemin>
|
||||
<valuemax>3</valuemax>
|
||||
<valuelist>
|
||||
<valueentry>
|
||||
<name>Left</name>
|
||||
<value>1</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Center</name>
|
||||
<value>2</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Right</name>
|
||||
<value>3</value>
|
||||
</valueentry>
|
||||
</valuelist>
|
||||
<value>2</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontcolor</parameterid>
|
||||
<name>Font Color</name>
|
||||
<value>
|
||||
<alpha>255</alpha>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>origin</parameterid>
|
||||
<name>Origin</name>
|
||||
<value>
|
||||
<horiz>0</horiz>
|
||||
<vert>0.34375</vert>
|
||||
</value>
|
||||
</parameter>
|
||||
</effect>
|
||||
<sourcetrack>
|
||||
<mediatype>video</mediatype>
|
||||
</sourcetrack>
|
||||
</generatoritem>";
|
||||
|
||||
string xmlTrackStructure3b =
|
||||
@"<generatoritem>
|
||||
<start>135</start>
|
||||
<end>219</end>
|
||||
<effect id='subtitle'>
|
||||
<name>Text</name>
|
||||
<effectid>Text</effectid>
|
||||
<effectcategory>Text</effectcategory>
|
||||
<effecttype>generator</effecttype>
|
||||
<mediatype>video</mediatype>
|
||||
<parameter>
|
||||
<parameterid>str</parameterid>
|
||||
<name>Text</name>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</effect>
|
||||
</generatoritem>";
|
||||
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.LoadXml(xmlStructure);
|
||||
|
||||
XmlNode videoNode = xml.DocumentElement.SelectSingleNode("sequence/media/video");
|
||||
|
||||
int number = 1;
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
XmlNode track = xml.CreateElement("track");
|
||||
if (number == 1)
|
||||
track.InnerXml = xmlTrackStructure3a;
|
||||
else
|
||||
track.InnerXml = xmlTrackStructure3b;
|
||||
|
||||
double frameRate = Configuration.Settings.General.DefaultFrameRate;
|
||||
XmlNode start = track.SelectSingleNode("generatoritem/start");
|
||||
start.InnerText = ((int)Math.Round(p.StartTime.TotalSeconds*frameRate)).ToString();
|
||||
|
||||
XmlNode end = track.SelectSingleNode("generatoritem/end");
|
||||
end.InnerText = ((int)Math.Round(p.EndTime.TotalSeconds * frameRate)).ToString();
|
||||
|
||||
XmlNode text = track.SelectSingleNode("generatoritem/effect/parameter[parameterid='str']/value");
|
||||
text.InnerText = Utilities.RemoveHtmlTags(p.Text);
|
||||
|
||||
XmlNode effect = track.SelectSingleNode("generatoritem/effect");
|
||||
if (effect != null && effect.Attributes["id"] != null)
|
||||
effect.Attributes["id"].InnerText = "Subtitle" + number.ToString();
|
||||
|
||||
videoNode.AppendChild(track);
|
||||
number++;
|
||||
}
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
XmlTextWriter writer = new XmlTextWriter(ms, Encoding.UTF8);
|
||||
writer.Formatting = Formatting.Indented;
|
||||
xml.Save(writer);
|
||||
string xmlAsText = Encoding.UTF8.GetString(ms.ToArray()).Trim();
|
||||
xmlAsText = xmlAsText.Replace("xmeml[]", "xmeml");
|
||||
return xmlAsText;
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
FrameRate = Configuration.Settings.General.DefaultFrameRate;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
lines.ForEach(line => sb.AppendLine(line));
|
||||
XmlDocument xml = new XmlDocument();
|
||||
try
|
||||
{
|
||||
xml.LoadXml(sb.ToString());
|
||||
|
||||
if (xml.DocumentElement.SelectSingleNode("sequence/rate") != null && xml.DocumentElement.SelectSingleNode("sequence/rate/timebase") != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
FrameRate = double.Parse(xml.DocumentElement.SelectSingleNode("sequence/rate/timebase").InnerText);
|
||||
}
|
||||
catch
|
||||
{
|
||||
FrameRate = Configuration.Settings.General.DefaultFrameRate;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (XmlNode node in xml.SelectNodes("xmeml/sequence/media/video/track"))
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (XmlNode generatorItemNode in node.SelectNodes("generatoritem"))
|
||||
{
|
||||
XmlNode rate = generatorItemNode.SelectSingleNode("rate");
|
||||
if (rate != null)
|
||||
{
|
||||
XmlNode timebase = rate.SelectSingleNode("timebase");
|
||||
if (timebase != null)
|
||||
FrameRate = double.Parse(timebase.InnerText);
|
||||
}
|
||||
|
||||
double startFrame = 0;
|
||||
double endFrame = 0;
|
||||
XmlNode startNode = generatorItemNode.SelectSingleNode("start");
|
||||
if (startNode != null)
|
||||
startFrame = double.Parse(startNode.InnerText);
|
||||
|
||||
XmlNode endNode = generatorItemNode.SelectSingleNode("end");
|
||||
if (endNode != null)
|
||||
endFrame = double.Parse(endNode.InnerText);
|
||||
|
||||
string text = string.Empty;
|
||||
foreach (XmlNode parameterNode in generatorItemNode.SelectNodes("effect/parameter[parameterid='str']"))
|
||||
{
|
||||
XmlNode valueNode = parameterNode.SelectSingleNode("value");
|
||||
if (valueNode != null)
|
||||
text += valueNode.InnerText;
|
||||
}
|
||||
if (text.Length > 0)
|
||||
{
|
||||
subtitle.Paragraphs.Add(new Paragraph(text, Convert.ToDouble((startFrame / FrameRate) *1000), Convert.ToDouble((endFrame / FrameRate) * 1000)));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
catch
|
||||
{
|
||||
_errorCount = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,8 +90,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
"</generatoritem>";
|
||||
|
||||
string xmlTrackStructure2 =
|
||||
@"<track>
|
||||
<generatoritem id='Subtitle Edit'>
|
||||
@"<generatoritem id='Subtitle Edit'>
|
||||
<name>edit 'B subtitle</name>
|
||||
<duration>3000</duration>
|
||||
<rate>
|
||||
@ -142,7 +141,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
<parameter>
|
||||
<parameterid>str</parameterid>
|
||||
<name>Text</name>
|
||||
<value> imported text from: small.srt</value>
|
||||
<value></value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontname</parameterid>
|
||||
@ -331,6 +330,131 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
</sourcetrack>
|
||||
</generatoritem>";
|
||||
|
||||
string xmlTrackStructure3a =
|
||||
@"<generatoritem>
|
||||
<name>Text</name>
|
||||
<duration>3600</duration>
|
||||
<rate>
|
||||
<ntsc>TRUE</ntsc>
|
||||
<timebase>30</timebase>
|
||||
</rate>
|
||||
<in>1650</in>
|
||||
<out>1784</out>
|
||||
<start>0</start>
|
||||
<end>134</end>
|
||||
<enabled>TRUE</enabled>
|
||||
<anamorphic>FALSE</anamorphic>
|
||||
<alphatype>black</alphatype>
|
||||
<effect id = 'subtitle'>
|
||||
<name>Text</name>
|
||||
<effectid>Text</effectid>
|
||||
<effectcategory>Text</effectcategory>
|
||||
<effecttype>generator</effecttype>
|
||||
<mediatype>video</mediatype>
|
||||
<parameter>
|
||||
<parameterid>str</parameterid>
|
||||
<name>Text</name>
|
||||
<value>If you look at the Lindy Hop you'll see a couple just moving</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontname</parameterid>
|
||||
<name>Font</name>
|
||||
<value>Futura</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontsize</parameterid>
|
||||
<name>Size</name>
|
||||
<valuemin>0</valuemin>
|
||||
<valuemax>1000</valuemax>
|
||||
<value>36</value></parameter>
|
||||
<parameter>
|
||||
<parameterid>fontstyle</parameterid>
|
||||
<name>Style</name>
|
||||
<valuemin>1</valuemin>
|
||||
<valuemax>4</valuemax>
|
||||
<valuelist>
|
||||
<valueentry>
|
||||
<name>Plain</name>
|
||||
<value>1</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Bold</name>
|
||||
<value>2</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Italic</name>
|
||||
<value>3</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Bold/Italic</name>
|
||||
<value>4</value>
|
||||
</valueentry>
|
||||
</valuelist>
|
||||
<value>3</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontalign</parameterid>
|
||||
<name>Alignment</name>
|
||||
<valuemin>1</valuemin>
|
||||
<valuemax>3</valuemax>
|
||||
<valuelist>
|
||||
<valueentry>
|
||||
<name>Left</name>
|
||||
<value>1</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Center</name>
|
||||
<value>2</value>
|
||||
</valueentry>
|
||||
<valueentry>
|
||||
<name>Right</name>
|
||||
<value>3</value>
|
||||
</valueentry>
|
||||
</valuelist>
|
||||
<value>2</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>fontcolor</parameterid>
|
||||
<name>Font Color</name>
|
||||
<value>
|
||||
<alpha>255</alpha>
|
||||
<red>255</red>
|
||||
<green>255</green>
|
||||
<blue>255</blue>
|
||||
</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<parameterid>origin</parameterid>
|
||||
<name>Origin</name>
|
||||
<value>
|
||||
<horiz>0</horiz>
|
||||
<vert>0.34375</vert>
|
||||
</value>
|
||||
</parameter>
|
||||
</effect>
|
||||
<sourcetrack>
|
||||
<mediatype>video</mediatype>
|
||||
</sourcetrack>
|
||||
</generatoritem>";
|
||||
|
||||
string xmlTrackStructure3b =
|
||||
@"<generatoritem>
|
||||
<start>135</start>
|
||||
<end>219</end>
|
||||
<effect id='subtitle'>
|
||||
<name>Text</name>
|
||||
<effectid>Text</effectid>
|
||||
<effectcategory>Text</effectcategory>
|
||||
<effecttype>generator</effecttype>
|
||||
<mediatype>video</mediatype>
|
||||
<parameter>
|
||||
<parameterid>str</parameterid>
|
||||
<name>Text</name>
|
||||
<value></value>
|
||||
</parameter>
|
||||
</effect>
|
||||
</generatoritem>";
|
||||
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.LoadXml(xmlStructure);
|
||||
|
||||
@ -340,7 +464,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
XmlNode track = xml.CreateElement("track");
|
||||
track.InnerXml = xmlTrackStructure;
|
||||
track.InnerXml = xmlTrackStructure2;
|
||||
|
||||
double frameRate = Configuration.Settings.General.DefaultFrameRate;
|
||||
XmlNode start = track.SelectSingleNode("generatoritem/start");
|
||||
@ -353,7 +477,8 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
text.InnerText = Utilities.RemoveHtmlTags(p.Text);
|
||||
|
||||
XmlNode effect = track.SelectSingleNode("generatoritem/effect");
|
||||
effect.Attributes["id"].InnerText = "Subtitle" + number.ToString();
|
||||
if (effect != null && effect.Attributes["id"] != null)
|
||||
effect.Attributes["id"].InnerText = "Subtitle" + number.ToString();
|
||||
|
||||
videoNode.AppendChild(track);
|
||||
number++;
|
||||
|
@ -17,10 +17,12 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
new SubRip(),
|
||||
new AdobeEncore(),
|
||||
new AdobeEncoreTab(),
|
||||
new DCSubtitle(),
|
||||
new DvdStudioPro(),
|
||||
new DvdSubtitle(),
|
||||
// new Ebu(),
|
||||
new FinalCutProXml(),
|
||||
new FinalCutProTestXml(),
|
||||
new MicroDvd(),
|
||||
new MPlayer2(),
|
||||
new OpenDvt(),
|
||||
@ -46,6 +48,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
new UnknownSubtitle3(),
|
||||
new UnknownSubtitle4(),
|
||||
new UnknownSubtitle5(),
|
||||
new UnknownSubtitle6(),
|
||||
new AbcIViewer(),
|
||||
new Csv(),
|
||||
new TimeXml(),
|
||||
|
166
src/Logic/SubtitleFormats/UnknownSubtitle6.cs
Normal file
166
src/Logic/SubtitleFormats/UnknownSubtitle6.cs
Normal file
@ -0,0 +1,166 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
public class UnknownSubtitle6 : SubtitleFormat
|
||||
{
|
||||
enum ExpectingLine
|
||||
{
|
||||
TimeCodes,
|
||||
BeforeText,
|
||||
Text
|
||||
}
|
||||
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".titl"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "Unknown 6"; }
|
||||
}
|
||||
|
||||
public override bool HasLineNumber
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
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 > _errorCount;
|
||||
}
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
|
||||
|
||||
const string paragraphWriteFormat = "{0:00}:{1:00}:{2:00}.{3:00}, {4:00}:{5:00}:{6:00}.{7:00}{8}{9}";
|
||||
|
||||
//00:00:07.00, 00:00:12.00
|
||||
//Welche Auswirkung Mikroversicherungen auf unsere Klienten hat? Lassen wir sie für sich selber sprechen!
|
||||
//
|
||||
//00:00:22.00, 00:00:27.00
|
||||
//Arme Menschen in Uganda leben oft in schlechten Unterkünften.
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine(" " + subtitle.Paragraphs.Count.ToString() + " 4 1234 ");
|
||||
sb.AppendLine(@"NORMAL
|
||||
00:00:00.00
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SRPSKI
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
00:00:00.00
|
||||
26.11.2008 18:54:15");
|
||||
|
||||
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
string firstLine = string.Empty;
|
||||
string secondLine = string.Empty;
|
||||
string[] lines = p.Text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
if (lines.Length > 2)
|
||||
{
|
||||
lines = Utilities.AutoBreakLine(p.Text).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
if (lines.Length > 0)
|
||||
firstLine = lines[0];
|
||||
if (lines.Length > 1)
|
||||
secondLine = lines[1];
|
||||
|
||||
string text = p.Text.Replace(Environment.NewLine, "|");
|
||||
|
||||
sb.AppendLine(string.Format(" {0} {1} " + Environment.NewLine +
|
||||
"1 0 0 0 0 0"+ Environment.NewLine +
|
||||
"{2}" + Environment.NewLine +
|
||||
"{3}", p.StartTime.TotalMilliseconds, p.EndTime.TotalMilliseconds, firstLine, secondLine));
|
||||
}
|
||||
return sb.ToString().Trim(); //.Replace(Environment.NewLine, "\n");
|
||||
}
|
||||
|
||||
private int RoundTo2Cifres(int milliseconds)
|
||||
{
|
||||
int rounded = (int)Math.Round((double)milliseconds / 10);
|
||||
return rounded;
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
var regexBeforeText = new Regex(@"^\d\s+\d\s+\d\s+\d\s+\d\s+\d$", RegexOptions.Compiled);
|
||||
var regexTimeCodes = new Regex(@"^\d+\s+\d+$", RegexOptions.Compiled);
|
||||
|
||||
var paragraph = new Paragraph();
|
||||
ExpectingLine expecting = ExpectingLine.TimeCodes;
|
||||
_errorCount = 0;
|
||||
|
||||
subtitle.Paragraphs.Clear();
|
||||
foreach (string line in lines)
|
||||
{
|
||||
|
||||
string s = line.Trim();
|
||||
if (regexTimeCodes.IsMatch(s))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(paragraph.Text))
|
||||
subtitle.Paragraphs.Add(paragraph);
|
||||
|
||||
paragraph = new Paragraph();
|
||||
string[] parts = s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
paragraph.StartTime.TotalMilliseconds = long.Parse(parts[0]);
|
||||
paragraph.EndTime.TotalMilliseconds = long.Parse(parts[1]);
|
||||
expecting = ExpectingLine.BeforeText;
|
||||
}
|
||||
catch
|
||||
{
|
||||
expecting = ExpectingLine.TimeCodes;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (regexBeforeText.IsMatch(s))
|
||||
{
|
||||
expecting = ExpectingLine.Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (expecting == ExpectingLine.Text)
|
||||
{
|
||||
if (s.Length > 0)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(paragraph.Text))
|
||||
paragraph.Text += Environment.NewLine + s;
|
||||
else
|
||||
paragraph.Text = s;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(paragraph.Text))
|
||||
subtitle.Paragraphs.Add(paragraph);
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user