mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-28 06:52:35 +01:00
Added two new subtitle formats + fixed bug in SSA/ASS style manager
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1278 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
3226a5a724
commit
38f38e631f
@ -333,7 +333,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(p.Extra) && ssaStyle.Name.TrimStart('*') == "Default")
|
if (string.IsNullOrEmpty(p.Extra) && ssaStyle.Name.TrimStart('*') == "Default")
|
||||||
count++;
|
count++;
|
||||||
else if (ssaStyle.Name.TrimStart('*').ToLower() == p.Extra.TrimStart('*').ToLower())
|
else if (p.Extra != null && ssaStyle.Name.TrimStart('*').ToLower() == p.Extra.TrimStart('*').ToLower())
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
subItem = new ListViewItem.ListViewSubItem(item, count.ToString());
|
subItem = new ListViewItem.ListViewSubItem(item, count.ToString());
|
||||||
|
105
src/Logic/SubtitleFormats/JsonType3.cs
Normal file
105
src/Logic/SubtitleFormats/JsonType3.cs
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||||
|
{
|
||||||
|
class JsonType3 : SubtitleFormat
|
||||||
|
{
|
||||||
|
public override string Extension
|
||||||
|
{
|
||||||
|
get { return ".json"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Name
|
||||||
|
{
|
||||||
|
get { return "JSON Type 3"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
sb.Append("[");
|
||||||
|
int count = 0;
|
||||||
|
foreach (Paragraph p in subtitle.Paragraphs)
|
||||||
|
{
|
||||||
|
if (count > 0)
|
||||||
|
sb.Append(",");
|
||||||
|
sb.Append("{\"duration\":");
|
||||||
|
sb.Append(p.Duration.TotalMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||||
|
sb.Append(",\"content\":\"");
|
||||||
|
sb.Append(p.Text.Replace("\\", string.Empty).Replace("{", string.Empty).Replace("{", string.Empty).Replace("\"", "\\\"").Replace(Environment.NewLine, "\\n") + "\"");
|
||||||
|
sb.Append(",\"startOfParagraph\":false");
|
||||||
|
sb.Append(",\"startTime\":");
|
||||||
|
sb.Append(p.StartTime.TotalMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
|
||||||
|
sb.Append("}");
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
sb.Append("]");
|
||||||
|
return sb.ToString().Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LoadSubtitle(Subtitle subtitle, List<string> lines, string fileName)
|
||||||
|
{
|
||||||
|
_errorCount = 0;
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
foreach (string s in lines)
|
||||||
|
sb.Append(s);
|
||||||
|
int startIndex = sb.ToString().IndexOf("[{\"duration");
|
||||||
|
if (startIndex == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string text = sb.ToString().Substring(startIndex);
|
||||||
|
foreach (string line in text.Replace("},{", Environment.NewLine).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
|
||||||
|
{
|
||||||
|
string s = line.Trim() + "}";
|
||||||
|
string start = Json.ReadTag(s, "startTime");
|
||||||
|
string duration = Json.ReadTag(s, "duration");
|
||||||
|
string content = Json.ReadTag(s, "content");
|
||||||
|
if (start != null && duration != null && content != null)
|
||||||
|
{
|
||||||
|
double startSeconds;
|
||||||
|
double durationSeconds;
|
||||||
|
if (double.TryParse(start, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out startSeconds) &&
|
||||||
|
double.TryParse(duration, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out durationSeconds) &&
|
||||||
|
content != null)
|
||||||
|
{
|
||||||
|
content = content.Replace("<br />", Environment.NewLine);
|
||||||
|
content = content.Replace("<br>", Environment.NewLine);
|
||||||
|
content = content.Replace("<br/>", Environment.NewLine);
|
||||||
|
content = content.Replace("\\n", Environment.NewLine);
|
||||||
|
subtitle.Paragraphs.Add(new Paragraph(content, startSeconds, startSeconds + durationSeconds));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_errorCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_errorCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subtitle.Renumber(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -47,6 +47,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
|||||||
new GpacTtxt(),
|
new GpacTtxt(),
|
||||||
new Json(),
|
new Json(),
|
||||||
new JsonType2(),
|
new JsonType2(),
|
||||||
|
new JsonType3(),
|
||||||
new MicroDvd(),
|
new MicroDvd(),
|
||||||
new MidwayInscriberCGX(),
|
new MidwayInscriberCGX(),
|
||||||
new MPlayer2(),
|
new MPlayer2(),
|
||||||
|
143
src/Logic/SubtitleFormats/UnknownSubtitle19.cs
Normal file
143
src/Logic/SubtitleFormats/UnknownSubtitle19.cs
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
|
||||||
|
{
|
||||||
|
class UnknownSubtitle19 : SubtitleFormat
|
||||||
|
{
|
||||||
|
public override string Extension
|
||||||
|
{
|
||||||
|
get { return ".xml"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Name
|
||||||
|
{
|
||||||
|
get { return "Unknown19"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ToTimeCode(TimeCode time)
|
||||||
|
{
|
||||||
|
return string.Format("{0:0.0}", time.TotalSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TimeCode DecodeTimeCode(string s)
|
||||||
|
{
|
||||||
|
return new TimeCode(TimeSpan.FromSeconds(double.Parse(s)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToText(Subtitle subtitle, string title)
|
||||||
|
{
|
||||||
|
//<Subtitle version="1.0" timeline="ee_disc1" name="Subtitle 1:" language="English" type="image">
|
||||||
|
// <Clip start="121.888" end="125.092" fileName="ee_disc1_subtitle_1/Subtitle_1.png" text="Hello.My name is Laura Knight-Jadcyzk" x="155" y="364" width="328" height="77"/>
|
||||||
|
// <Clip start="125.125" end="129.262" fileName="ee_disc1_subtitle_1/Subtitle_2.png" text="and welcome to the Éiriú Eolasbreathing and meditation program" x="145" y="364" width="348" height="77"/>
|
||||||
|
string xmlStructure =
|
||||||
|
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + Environment.NewLine +
|
||||||
|
"<Subtitle version=\"1.0\" timeline=\"ee_disc1\" name=\"Subtitle 1:\" language=\"English\" type=\"text\"></Subtitle>";
|
||||||
|
|
||||||
|
var xml = new XmlDocument();
|
||||||
|
xml.LoadXml(xmlStructure);
|
||||||
|
|
||||||
|
// int count = 1;
|
||||||
|
foreach (Paragraph p in subtitle.Paragraphs)
|
||||||
|
{
|
||||||
|
XmlNode paragraph = xml.CreateElement("Clip");
|
||||||
|
|
||||||
|
XmlAttribute attr = xml.CreateAttribute("start");
|
||||||
|
attr.InnerText = ToTimeCode(p.StartTime);
|
||||||
|
paragraph.Attributes.Append(attr);
|
||||||
|
|
||||||
|
attr = xml.CreateAttribute("end");
|
||||||
|
attr.InnerText = ToTimeCode(p.EndTime);
|
||||||
|
paragraph.Attributes.Append(attr);
|
||||||
|
|
||||||
|
//attr = xml.CreateAttribute("fileName");
|
||||||
|
//attr.InnerText = "ee_disc1_subtitle_1/Subtitle_" + count + ".png";
|
||||||
|
//paragraph.Attributes.Append(attr);
|
||||||
|
|
||||||
|
attr = xml.CreateAttribute("text");
|
||||||
|
attr.InnerText = Utilities.RemoveHtmlTags(p.Text);
|
||||||
|
paragraph.Attributes.Append(attr);
|
||||||
|
|
||||||
|
xml.DocumentElement.AppendChild(paragraph);
|
||||||
|
// count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ms = new MemoryStream();
|
||||||
|
var writer = new XmlTextWriter(ms, Encoding.UTF8) { 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;
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
lines.ForEach(line => sb.AppendLine(line));
|
||||||
|
|
||||||
|
string allText = sb.ToString();
|
||||||
|
if (!allText.Contains("</Subtitle>") || !allText.Contains("<Clip "))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var xml = new XmlDocument();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
xml.LoadXml(allText);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine(exception.Message);
|
||||||
|
_errorCount = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xml.DocumentElement == null)
|
||||||
|
{
|
||||||
|
_errorCount = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (XmlNode node in xml.DocumentElement.SelectNodes("Clip"))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (node.Attributes != null)
|
||||||
|
{
|
||||||
|
string text = node.Attributes.GetNamedItem("text").InnerText.Trim();
|
||||||
|
string start = node.Attributes.GetNamedItem("start").InnerText;
|
||||||
|
string end = node.Attributes.GetNamedItem("end").InnerText;
|
||||||
|
subtitle.Paragraphs.Add(new Paragraph(DecodeTimeCode(start), DecodeTimeCode(end), text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine(ex.Message);
|
||||||
|
_errorCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subtitle.Renumber(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -686,6 +686,7 @@
|
|||||||
<Compile Include="Logic\SubtitleFormats\FlashXml.cs" />
|
<Compile Include="Logic\SubtitleFormats\FlashXml.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\GpacTtxt.cs" />
|
<Compile Include="Logic\SubtitleFormats\GpacTtxt.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\HtmlSamiArray.cs" />
|
<Compile Include="Logic\SubtitleFormats\HtmlSamiArray.cs" />
|
||||||
|
<Compile Include="Logic\SubtitleFormats\JsonType3.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\NciCaption.cs" />
|
<Compile Include="Logic\SubtitleFormats\NciCaption.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\RhozetHarmonic.cs" />
|
<Compile Include="Logic\SubtitleFormats\RhozetHarmonic.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\Json.cs" />
|
<Compile Include="Logic\SubtitleFormats\Json.cs" />
|
||||||
@ -732,6 +733,7 @@
|
|||||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle17.cs" />
|
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle17.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\JsonType2.cs" />
|
<Compile Include="Logic\SubtitleFormats\JsonType2.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle18.cs" />
|
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle18.cs" />
|
||||||
|
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle19.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle5.cs" />
|
<Compile Include="Logic\SubtitleFormats\UnknownSubtitle5.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\OpenDvt.cs" />
|
<Compile Include="Logic\SubtitleFormats\OpenDvt.cs" />
|
||||||
<Compile Include="Logic\SubtitleFormats\AbcIViewer.cs" />
|
<Compile Include="Logic\SubtitleFormats\AbcIViewer.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user