mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Added new subtitle format
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1509 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
936e101dbe
commit
f317665839
@ -1,6 +1,6 @@
|
||||
Subtitle Edit Changelog
|
||||
|
||||
3.3 RC1 (15th November 2012)
|
||||
3.3 (? 2012)
|
||||
* NEW:
|
||||
* Added column commands to list view context menu - thx Seungki
|
||||
* Edit -> Reverse RTL start/end (fix punctuations)
|
||||
@ -13,7 +13,7 @@ Subtitle Edit Changelog
|
||||
* New setting in Options: "Max. chars/second"
|
||||
* New settings in Options regarding "Min. duration" + "Max. duration"
|
||||
* New settings in Options regarding syntax coloring
|
||||
* Many new subtitle formats (now 130+ formats supported!)
|
||||
* Many new subtitle formats (now 140+ formats supported!)
|
||||
* New settings in Options, center subtitle (in SE text boxes)
|
||||
* Tools -> Join subtitles (merge of multiple parts)
|
||||
* Tools -> Apply duration limits
|
||||
|
@ -678,7 +678,7 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
MainEditFind = "Control+F";
|
||||
MainEditFindNext = "F3";
|
||||
MainEditReplace = "Control+H";
|
||||
MainEditMultipleReplace = string.Empty;
|
||||
MainEditMultipleReplace = "Control+Alt+M";
|
||||
MainEditGoToLineNumber = "Control+G";
|
||||
MainEditRightToLeft = "Control+Shift+Alt+R";
|
||||
MainToolsFixCommonErrors = "Control+Shift+F";
|
||||
|
@ -139,6 +139,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
new UnknownSubtitle40(),
|
||||
new UnknownSubtitle41(),
|
||||
new UnknownSubtitle42(),
|
||||
new UnknownSubtitle43(),
|
||||
new UTSubtitleXml(),
|
||||
new Utx(),
|
||||
new UtxFrames(),
|
||||
|
@ -214,7 +214,6 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
paragraph.AppendChild(br);
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
System.Collections.Generic.Stack<XmlNode> styles = new Stack<XmlNode>();
|
||||
XmlNode currentStyle = xml.CreateTextNode(string.Empty);
|
||||
paragraph.AppendChild(currentStyle);
|
||||
|
@ -42,7 +42,13 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
|
||||
var nsmgr = new XmlNamespaceManager(xml.NameTable);
|
||||
nsmgr.AddNamespace("ttaf1", xml.DocumentElement.NamespaceURI);
|
||||
XmlNode div = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr).SelectSingleNode("ttaf1:div", nsmgr);
|
||||
|
||||
XmlNode div;
|
||||
var body = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr);
|
||||
if (body == null)
|
||||
div = xml.DocumentElement;
|
||||
else
|
||||
div = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr).SelectSingleNode("ttaf1:div", nsmgr);
|
||||
if (div == null)
|
||||
div = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr).FirstChild;
|
||||
int numberOfParagraphs = div.ChildNodes.Count;
|
||||
@ -138,7 +144,14 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
|
||||
var nsmgr = new XmlNamespaceManager(xml.NameTable);
|
||||
nsmgr.AddNamespace("ttaf1", xml.DocumentElement.NamespaceURI);
|
||||
XmlNode div = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr).SelectSingleNode("ttaf1:div", nsmgr);
|
||||
|
||||
XmlNode div;
|
||||
var body = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr);
|
||||
if (body == null)
|
||||
div = xml.DocumentElement;
|
||||
else
|
||||
div = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr).SelectSingleNode("ttaf1:div", nsmgr);
|
||||
|
||||
if (div == null)
|
||||
div = xml.DocumentElement.SelectSingleNode("//ttaf1:body", nsmgr).FirstChild;
|
||||
foreach (XmlNode node in div.ChildNodes)
|
||||
|
180
src/Logic/SubtitleFormats/UnknownSubtitle43.cs
Normal file
180
src/Logic/SubtitleFormats/UnknownSubtitle43.cs
Normal file
@ -0,0 +1,180 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||
{
|
||||
class UnknownSubtitle43 : SubtitleFormat
|
||||
{
|
||||
public override string Extension
|
||||
{
|
||||
get { return ".xml"; }
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get { return "Unknown 43"; }
|
||||
}
|
||||
|
||||
public override bool IsTimeBased
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
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("<subtitle"))
|
||||
{
|
||||
var xml = new XmlDocument();
|
||||
try
|
||||
{
|
||||
xml.LoadXml(xmlAsString);
|
||||
if (xml.DocumentElement.Name == "parfums")
|
||||
{
|
||||
return xml.DocumentElement.SelectNodes("subtitle").Count > 0;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static string ConvertToTimeString(TimeCode time)
|
||||
{
|
||||
return string.Format("{0}:{1:00}", (int)(time.TotalSeconds / 60), (int)(time.TotalSeconds % 60));
|
||||
}
|
||||
|
||||
|
||||
public override string ToText(Subtitle subtitle, string title)
|
||||
{
|
||||
var xml = new XmlDocument();
|
||||
xml.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?><parfums></parfums>");
|
||||
|
||||
int no = 0;
|
||||
foreach (Paragraph p in subtitle.Paragraphs)
|
||||
{
|
||||
XmlNode paragraph = xml.CreateElement("subtitle");
|
||||
string text = p.Text;
|
||||
|
||||
bool first = true;
|
||||
foreach (string line in text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
if (!first)
|
||||
{
|
||||
XmlNode br = xml.CreateElement("br");
|
||||
paragraph.AppendChild(br);
|
||||
}
|
||||
var textNode = xml.CreateTextNode(string.Empty);
|
||||
textNode.InnerText = line;
|
||||
paragraph.AppendChild(textNode);
|
||||
first = false;
|
||||
}
|
||||
|
||||
XmlAttribute end = xml.CreateAttribute("end");
|
||||
end.InnerText = ConvertToTimeString(p.EndTime);
|
||||
paragraph.Attributes.Append(end);
|
||||
|
||||
XmlAttribute start = xml.CreateAttribute("start");
|
||||
start.InnerText = ConvertToTimeString(p.StartTime);
|
||||
paragraph.Attributes.Append(start);
|
||||
|
||||
xml.DocumentElement.AppendChild(paragraph);
|
||||
no++;
|
||||
}
|
||||
|
||||
return ToUtf8XmlString(xml).Replace(" xmlns=\"\"", string.Empty);
|
||||
}
|
||||
|
||||
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||
{
|
||||
_errorCount = 0;
|
||||
|
||||
var sb = new StringBuilder();
|
||||
lines.ForEach(line => sb.AppendLine(line));
|
||||
var xml = new XmlDocument();
|
||||
xml.LoadXml(sb.ToString());
|
||||
|
||||
foreach (XmlNode node in xml.DocumentElement.SelectNodes("subtitle"))
|
||||
{
|
||||
try
|
||||
{
|
||||
var pText = new StringBuilder();
|
||||
foreach (XmlNode innerNode in node.ChildNodes)
|
||||
{
|
||||
switch (innerNode.Name)
|
||||
{
|
||||
case "br":
|
||||
pText.AppendLine();
|
||||
break;
|
||||
case "span":
|
||||
ReadSpan(pText, innerNode);
|
||||
break;
|
||||
|
||||
default:
|
||||
pText.Append(innerNode.InnerText);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string start = node.Attributes["start"].InnerText;
|
||||
string end = node.Attributes["end"].InnerText;
|
||||
var p = new Paragraph(GetTimeCode(start), GetTimeCode(end), pText.ToString().Replace(" ", " ").Replace(" ", " "));
|
||||
subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ex.Message);
|
||||
_errorCount++;
|
||||
}
|
||||
}
|
||||
subtitle.Renumber(1);
|
||||
}
|
||||
|
||||
private static void ReadSpan(StringBuilder pText, XmlNode innerNode)
|
||||
{
|
||||
if (innerNode.HasChildNodes)
|
||||
{
|
||||
foreach (XmlNode innerInnerNode in innerNode.ChildNodes)
|
||||
{
|
||||
if (innerInnerNode.Name == "br")
|
||||
{
|
||||
pText.AppendLine();
|
||||
}
|
||||
else if (innerInnerNode.Name == "span")
|
||||
{
|
||||
ReadSpan(pText, innerInnerNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
pText.Append(innerInnerNode.InnerText);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pText.Append(innerNode.InnerText);
|
||||
}
|
||||
}
|
||||
|
||||
public static TimeCode GetTimeCode(string s)
|
||||
{
|
||||
string[] arr = s.Split(':');
|
||||
if (arr.Length == 2)
|
||||
return new TimeCode(0, int.Parse(arr[0]), int.Parse(arr[1]), 0);
|
||||
if (arr.Length == 3)
|
||||
return new TimeCode(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]), 0);
|
||||
|
||||
return new TimeCode(0, 0, int.Parse(s), 0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -839,6 +839,7 @@
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle40.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle41.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle42.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle43.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle5.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\OpenDvt.cs" />
|
||||
<Compile Include="Logic\SubtitleFormats\AbcIViewer.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user